13
votes

I am in the process of writing a VoIP application for iOS but when App is in background it stops accepting calls. When the app is active again all the queued up messages start getting processed.

The following is what I have done.

When building the app I add Voice over IP as well as Audio and AirPlay to the plist file. Then I mark the websocket connection with NetworkServiceTypeVoIP as you can see here.

I have not set the keep alive timeout handler because registration doesn't matter if the app won't wake up to answer the call. Any help would be greatly appreciated.

It should be noted that this is my first Swift project and I'm not very familiar with the iOS platform.

3
Are you using a TCP socket as your VoIP socket? stackoverflow.com/a/7393083/624920Ryan Maloney
I am using a websocket so it is definitely TCP. You can find the code for the project here github.com/BetterVoice/phonertc/blob/master/src/ios/…Thomas Quintana

3 Answers

2
votes

To allow to work your app in background mode, you need to enable Voice over IP flag ON(Path : Go to target --> capabilities --> Background Modes). like as below.

enter image description here

And add following code in your project to support in background:

Step 1: Declare __block UIBackgroundTaskIdentifier bgTask as global variable.

Step 2: To add following code in applicationDidEnterBackground.

  - (void)applicationDidEnterBackground:(UIApplication *)application {

         bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
         bgTask = UIBackgroundTaskInvalid;
          }];

}

Step 3: Stop background task handler once apps come in foreground mode.

- (void)applicationWillEnterForeground:(UIApplication *)application {
  // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.

  [[UIApplication sharedApplication] endBackgroundTask:bgTask];

}
1
votes

Take a look at Apple documentation, you're probably interested in UIBackgroundModes=voip.

UPD:

From documentation:

To configure a VoIP app, you must do the following:

  1. Enable support for Voice over IP from the Background modes section of the Capabilities tab in your Xcode project. (You can also enable this support by including the UIBackgroundModes key with the voip value in your app’s Info.plist file.)
  2. Configure one of the app’s sockets for VoIP usage.
  3. Before moving to the background, call the setKeepAliveTimeout:handler: method to install a handler to be executed periodically. Your app can use this handler to maintain its service connection.
  4. Configure your audio session to handle transitions to and from active use.
0
votes

You may find your answer or some clue --> here <--

Properly have to research the following:

applicationDidEnterBackground
beginBackgroundTaskWithExpirationHandler