Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Backgrounding Not Working

Tags:

ios

voip

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.

like image 318
Thomas Quintana Avatar asked Jan 19 '15 15:01

Thomas Quintana


Video Answer


1 Answers

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];

}
like image 169
Jatin Patel - JP Avatar answered Oct 12 '22 10:10

Jatin Patel - JP