目前,对于处于后台模式的我的 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];
}];
}