3

I have a VoIP socket setup, it works properly even in suspended states, and pings server in every 10 minute.

But when the WiFi connection has broken, then I have no idea how to reconnect to the service, even in suspended state. The same goes for device restart.

Any experiences?

Geri Borbás
  • 15,810
  • 18
  • 109
  • 172

3 Answers3

3
  1. Bad WiFI: iOS doesn't let you choose the network to bind to your socket, meaning:
    • If the device has only 2G/3G/4G network, it will bind your socket over it.
    • If you also has WiFi (also broken WiFi) it will bind your socket over it even though its bad for you.
  2. Reconnecting: You may use your 10 minutes KeepAlive block in UIApplication in order to try and fix your connection every 10 minutes: Wake up every 10 minutes and try to reconnect.
  3. App launched automatically: After device reboot, VoIP app DOES get to run, if it ran before the reboot. (This VoIP app privilegue also launch your app after a crash)
  4. Note: You can detect if you were launched automatically by asking UIApplication its applicationState, in applicationDidFinishLaunching.
  5. Tip: Use Background tasks while performing actions at background.
  6. Links:
Community
  • 1
  • 1
Avishay Cohen
  • 2,418
  • 1
  • 22
  • 40
0

Well if the device gets restarted there is no way to start your app again. The user will have to start your app.

When you connection get dropped, due to som kind of netwerk error and your app is running in the background iOS will suspend your app. Thus the user will have to start the app again to get this working.

rckoenes
  • 69,092
  • 8
  • 134
  • 166
-1

setKeepAliveTimeout:handler:

Configures a periodic handler for VoIP applications.

  • (BOOL)setKeepAliveTimeout:(NSTimeInterval)timeout handler:(void (^)(void))keepAliveHandler

Parameters

timeout

The maximum interval (measured in seconds) at which your application should be woken up to check its VoIP connection. The minimum acceptable timeout value is 600 seconds. keepAliveHandler A block that performs the tasks needed to maintain your VoIP network connection. Setting this parameter to nil releases the current handler block and prevents UIKit from scheduling the next wake.

Return Value

YES if the handler was installed or NO if it was not.

Discussion

A voice-over-IP (VoIP) application can use this method to install a handler whose job is to maintain the application’s network connection with a VoIP server. This handler is guaranteed to be called before the specified timeout value but may be called at a slightly different time interval in order to better align execution of your handler with other system tasks, and thereby save power. Your handler has a maximum of 10 seconds to perform any needed tasks and exit. If it does not exit before time expires, the application is suspended.

Timeout values and handlers are not persisted between application launches. Therefore, if your application is terminated for any reason, you must reinstall the handler during the next launch cycle.

For calls to this method to succeed, the application must have the voip value in the array associated with the UIBackgroundModes key in its Info.plist file. Calling this method replaces the previously installed handler and timeout values, if any.

Availability

Available in iOS 4.0 and later.

Declared In

UIApplication.h