2
votes

Recently I have to implement background working app with voip. For that I use PJSip. Right now I have done registering and handling calls working perfectly when app is running.

When app goes to the background, by first 10 minuts works fine -> new incomming calls are captured and are send as local notifications - so this is fine. After 10 minutes sip stops working and incomming calls doesn't arrives as well.

Could you help me with this?

I have check "bacground working - VoiP" I have done keep alive in pjsip from siphon2 example application.

I have also:

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [[PjSipService service] setIsInBackground:YES];
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    int KEEP_ALIVE_INTERVAL = 600;

    [self performSelectorOnMainThread:@selector(keepAlive) withObject:nil waitUntilDone:YES];
    NSLog(@"startingKeepAliveTimeout1");

    [application setKeepAliveTimeout:KEEP_ALIVE_INTERVAL handler: ^{
        NSLog(@"startingKeepAliveTimeout2");

        [self performSelectorOnMainThread:@selector(keepAlive) withObject:nil waitUntilDone:YES];
    }];


    __block UIBackgroundTaskIdentifier bgTask;

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


    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        //[self deregis];
        [application endBackgroundTask: bgTask]; //End the task so the system knows that you are done with what you need to perform
        bgTask = UIBackgroundTaskInvalid; //Invalidate the background_task

         NSLog(@"\n\nRunning in the background!\n\n");
    });
}

"keepAlive" function is empty. I've read that for this function keepAlive is enought - but without background task it doesn't work even 10 minuts.

Application has to works in iOS7 and iOS6

4

4 Answers

1
votes

Apps running in background, is performed using setKeepAliveTimeout method in IOS. But from later versions, setKeepAliveTimeout method is deprecated.

You want to use Remote notifications to receive incoming call. particularly for VOIP incoming calls, apple introduced Callkit framework. please follow that framework to accept incoming calls while your VOIP App is in background state.

https://www.raywenderlich.com/150015/callkit-tutorial-ios

0
votes

I am working on the same project with same requirements and I came across with the same issue recently. I tried many different solutions and finally I found something that is working for now.

Please note that I recently found this solution and I am working on this. I haven't consider the reaction of this code at least for now.

Sample Code :

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [self sipConnect];
    backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
        [self endBackgroundTask];
    }];
}

-(void) endBackgroundTask
{
    [[UIApplication sharedApplication] endBackgroundTask:backgroundTask];
    backgroundTask = UIBackgroundTaskInvalid;
}
0
votes

You probably use UPD. To make sure you use TCP, when setting up your registrar you need to specify something like this sip:ip_address:port;transport=tcp

0
votes

Apple has deprecated keepAliveTimeoutHandler. To receive calls when applicationDidEnterBackground you have to use PushKit framework. Read documentation for more information here.