如果强制退出并重启设备,Voip Pushkit通知将不会重新启动应用程序

mca*_*oun 9 notifications voip apple-push-notifications ios ios8

如果用户强行退出应用程序(通过在多任务界面中轻扫)并且设备重新启动,我无法获取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];
    // ... more code to read the token ...
}

- (void)pushRegistry:(PKPushRegistry *)registry
    didReceiveIncomingPushWithPayload:(PKPushPayload *)payload
    forType:(NSString *)type {
    // ... logging to check if notification is received ...
}
Run Code Online (Sandbox Code Playgroud)

此外,我在后台模式中启用了"IP语音"和"远程通知".

我知道像Whatsapp这样的其他应用程序能够在这种情况下重新启动,所以我不明白我做错了什么.

在相关的说明中,它没有帮助做以下1)强制退出2)发送一个pushkit通知 - 将收到3)重新启动.该应用程序不会重新启动,新的推送通知仍然不会重新启动它.

mca*_*oun 4

在我使用 AdHoc 配置文件测试应用程序(并从 iTunes 安装)后,通过 prod gateway.push.apple.com 而不是 gateway.sandbox.push.apple.com 提供的 Voip 推送通知开始唤醒强制退出的应用程序。重新启动后的应用程序。

该操作系统显然以不同的方式处理开发和生产。

进一步查看 APSD 日志,我发现使用开发配置文件时会打印以下内容:

: XXXX-XX-XX XX:XX:XX +0300 apsd[97]:
这些启用的主题已被删除 {( "YOUR_BUNLE_IDENTIFIER" )}

使用临时配置文件时不会发生这种情况。