目前,我的Voip应用在后台模式下使用以下代码,以保持Voip应用程序在进入后台或进入后台并锁定电话时保持唤醒状态,并在呼叫到达时显示通知。我发现在iOS 8及更高版本中,setKeepAliveTimeout不再起作用,我们需要使用Pushkit,有没有办法在不编写服务器端代码的情况下使用PushKit?
- (void)registerKeepAliveHandler:(UIApplication*) application
{
LogInfo(TAG_MAIN, @"Registering KeepAliveTimeout");
[application setKeepAliveTimeout:600 handler:^{
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_KEEPALIVE_RECEIVED object:nil];
NSMutableString* statusStr = [[NSMutableString alloc] init];
switch ([[UIApplication sharedApplication] applicationState]) {
case UIApplicationStateActive:
[statusStr appendString:@"foreground"];
break;
case UIApplicationStateInactive:
[statusStr appendString:@"inactive"];
break;
case UIApplicationStateBackground:
[statusStr appendString:@"background"];
break;
default:
assert(0);
break;
}
LogInfo(TAG_MAIN, @"===================================== Keepalive received in %@ application status ===============================", statusStr);
[UIApplication getIPAddress];
LogInfo(TAG_MAIN, @"%@", [[UIDevice currentDevice] batteryInfo]);
[[SipEngine sharedInstance] isServerReachable];
[[SipEngine sharedInstance] isRegistered];
[[SipEngine sharedInstance] startStopRegistration];
[[[SipEngine sharedInstance] registration] registering];
}];
}