2
votes

I am working on a SIP Calling app. I used siphon app project that implements open source pjsip library. I am able to run Application successfully in foreground mode, for Device as well as Simulator.

In order to run the application in Background Mode for VOIP, I am following this RayWenderlich Tutorial. As per the Apple Documentation, we have to follow these 4 steps :

  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.

I already implemented this first step :

enter image description here

But I am not getting any idea on how to implement the next three steps in order to receive the SIP Call in Background Mode. Got the logic behind these three steps but didn't find any source code for the implementation.

Have anyone worked on this before?

2

2 Answers

1
votes

Here keepAlive example for siphon project I used too. If you modify this project you can do all other stuff you want in - (void)processCallState:(NSNotification *)notification callback.

- (void)keepAlive {
    /* Register this thread if not yet */
    if (!pj_thread_is_registered()) {
        static pj_thread_desc   thread_desc;
        static pj_thread_t     *thread;
        pj_thread_register("ipjsua", thread_desc, &thread);
    }
    pjsua_acc_set_registration(0, PJ_TRUE);
    NSLog(@"Keep Alive");
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    /* Send keep alive manually at the beginning of background */
    [self performSelectorOnMainThread:@selector(keepAlive) withObject:nil waitUntilDone:YES];

    /* iOS requires that the minimum keep alive interval is 600s */
    [application setKeepAliveTimeout:600 handler: ^{
        [self performSelectorOnMainThread:@selector(keepAlive)
                               withObject:nil waitUntilDone:YES];
    }];
}

Do not forget set keepAlive interval in siphon settings to 600.

0
votes

Steps 2 & 4 are done for you in pjsip itself, so nothing for you to do.

Step 3 is the only one you need to implement. Step 3 is required because when in background mode, none of the IOS timers will fire, so the sip re-registration never happens. So you need to setup the ios "special" background timer to call back into pjsip to say please register with the sip ragistar. So you setup your keep alive timeout to something smaller than you reregistration time.

Examples of step 3 can be found in the pjsip sample pjsua application and you should be able to find it in the siphon application as well.

So normally you add in support into your app delegate class in the applicationDidEnterBackground callback. See pjsua for an example.

Make sure you are using a tcp connection as udp doesn't work in the background.