即使应用程序被杀死并发送本地通知,我也必须在后台监视呼叫。有没有办法继续做这样的事情?我的意思是超过10分钟。到目前为止,我可以监控通话并发送通知,但只能在没有杀死应用程序的情况下。先谢谢了。
这是我的做法:
- (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];
}
}];
}