Monitoring calls even if the app gets killed

258 Views Asked by At

I have to monitore the calls in background even when the app gets killed and send a local notification. Is that any way to keep do such thing like that? I mean beyond the 10 minutes too. So far, I can monitoring the calls and send the notification but only without killed the app. Thanks in advanced.

Here's how I'm doing:

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

    UIBackgroundTaskIdentifier bgTask = 0;

    UIApplication  *app = [UIApplication sharedApplication];

    bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
        [app endBackgroundTask:bgTask];
    }];

    [self startMonitoringCalls];
}

-(void)startMonitoringCalls
{

    callCenter = [[CTCallCenter alloc] init];

    [callCenter setCallEventHandler:^(CTCall *call) {
        if ([[call callState] isEqual:CTCallStateConnected]) {
            NSLog(@"Get called");
        } else if ([[call callState] isEqual:CTCallStateDisconnected]) {

            UILocalNotification *notification = [[UILocalNotification alloc] init];
            notification.fireDate = [NSDate date];
            notification.alertBody = @"Would you like to...";
            [[UIApplication sharedApplication] scheduleLocalNotification:notification];

        }
    }];

}
1

There are 1 best solutions below

0
On BEST ANSWER

Foursquare is using the location background mode, which under some circumstances will relaunch the app if its been killed. However there is no equivalent for monitoring phone calls. The best you could hope for is to have a legitimate use for being able to use one of the background modes that would enable you to run your call monitoring code and re-launch your app when killed. If you don't have a legitimate use your app would be rejected from the app store.