1
votes

We are developing an iOS app that makes VoIP calls using pjsip. All works fine when the app is in the foreground or if we start the call in the foreground and then put the app in the background.

But when the app is in the background we need to start a VoIP call when a certain connection is made from a BLE device.

So basically the BLE devices talks to the app and it asks it to start the call. This is not working.

The audio in bg is enabled.

Is this at all possible on iOS? I cannot find any reference to this situation in the Apple's docs

We are using TCP for the VoIP connection.

3
setKeepAliveTimeout that is found in many articles related to VoIP in the bg is deprecatedmemical
Have you solve this issue? Any update?Mike D3ViD Tyson

3 Answers

0
votes

You have to use PushKit(VoIP Push Notification) to wake up your VoIP app in background. Apple strongly recommends to use PushKit and pjsip added some modification to support it.

Voice Over IP (VoIP) Best Practices - Apple

PushKit guide, to accept calls in the background after kCFStreamNetworkServiceTypeVoIP is deprecated (iOS 10/iOS 9) - pjsip

0
votes

I am not sure how to do that in your specific case, but I assume that something like CallKit can help you out.

With CallKit you sync all the VOIP features of your app with native iOS. Which means if you can start a native call with the BLE device, you can definitely start a call from the app, while it is in the background, using that device.

You can read more about it here:

Apple Documentation for an INStartAudioCallIntent

WWDC Video

EDIT:

On Apple's Documentation for CallKit

Making Outgoing Calls A user can initiate an outgoing call with a VoIP app in any of the following ways:

  1. Performing an interaction within the app

  2. Opening a link with a supported custom URL scheme

  3. Initiating a VoIP call using Siri

0
votes

This is from the official docs and might help you out. https://trac.pjsip.org/repos/wiki/Getting-Started/iPhone#keepalive

As the process is normally suspended when application is in the background, the worker thread that handles TCP keepalive timer is also suspended. So basically application needs to schedule periodic wakeup to allow the library send TCP keep-alive.

Modify your AppDelegate.m to something like this-

- (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("mainthread", thread_desc, &thread);
    }

    /* Simply sleep for 5s, give the time for library to send transport
     * keepalive packet, and wait for server response if any. Don't sleep
     * too short, to avoid too many wakeups, because when there is any
     * response from server, app will be woken up again (see also #1482).
     */
    pj_thread_sleep(5000);
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    /* Send keep alive manually at the beginning of background */
    pjsip_endpt_send_raw*(...);

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