如果用户强行退出应用程序(通过在多任务界面中轻扫)并且设备重新启动,我无法获取voip pushkit通知来重新启动应用程序.
但是,我可以在以下场景中使用voip pushkit通知:
该应用程序被强制退出然后推送通知到达.该应用程序将立即重新启动.在这种情况下,标准推送通知无法唤醒应用程序.
该应用程序处于后台/暂停状态,设备重新启动.由于Voip模式,应用程序将在设备重启时重新启动(我可以在Xcode活动监视器中看到该过程).这里需要一个技巧来正确处理pushkit通知,这在http://blog.biokoda.com/post/114315188985/ios-and-pushkit中用这些术语描述"在初始化PushKit之前启动后台任务.收到PushKit令牌时完成此任务"
不知何故,当组合这两个(设备重启和app强制退出)时,pushkit通知似乎不会重新启动应用程序.另外,当查看Xcode中的设备日志时,我没有得到来自apsd的日志,说该通知是由系统处理的.
这是我的代码:
@implementation AppDelegate
{
UIBackgroundTaskIdentifier bgTask;
}
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIApplication* app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
dispatch_async(dispatch_get_global_queue(
DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
while (true) {
;
}
});
// Initialize pushkit
PKPushRegistry *pushRegistry =
[[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
pushRegistry.delegate = self;
pushRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
return YES;
}
- (void)pushRegistry:(PKPushRegistry *)registry
didUpdatePushCredentials:(PKPushCredentials *)credentials
forType:(NSString *)type{
UIApplication* app = [UIApplication sharedApplication];
[app endBackgroundTask:bgTask]; …Run Code Online (Sandbox Code Playgroud)