应用程序终止和设备重启后 PushKit 通知未到达 [英] PushKit notification not arriving after application kill AND device reboot

查看:26
本文介绍了应用程序终止和设备重启后 PushKit 通知未到达的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 iOS 应用程序即使关闭也能成功接收 VoIP 推送通知,这要归功于 PushKit.失败时只有一种情况:

My iOS application successfully receives VoIP push notifications even if it is closed, thanks to PushKit. There is only one condition when it fails:

如果我通过标准任务切换器将我的应用刷出(终止)并重新启动我的设备.

If I swipe my app out(terminate) throught the standard task switcher AND reboot my device.

起初,我在重新启动设备后就遇到了这个问题,如本问题所述:解决启动后推送通知传送失败后台任务 hack 帮助了我,非常感谢作者,可惜我无法添加任何分数.

At first, I had this problem simply after rebooting the device, as described in this question: Troubleshooting post-boot push notification delivery failures A background task hack helped me, many thanks to the author, too bad I couldn't add any score.

现在我被这个问题困住了.通知不会到达,因为 didFinishLaunchingWithOptions 在设备启动时不会被调用,如果用户在重新启动他/她的设备之前终止了应用程序.

Now I am stuck with this problem. Notifications won't arrive because didFinishLaunchingWithOptions is simply not called at device boot up if user terminated the app before rebooting his/her device.

检查我的应用的后台功能:

my app's background capabilities that are checked:

  • IP 语音
  • 远程通知

这是我的代码片段:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    PKPushRegistry *pushRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
    pushRegistry.delegate = self;
    pushRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
    self.backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
        [[UIApplication sharedApplication] endBackgroundTask:self.backgroundTask];
        self.backgroundTask = UIBackgroundTaskInvalid;
    }];
    return YES;
}

- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type {
    [[UIApplication sharedApplication] endBackgroundTask:self.backgroundTask];
    self.backgroundTask = UIBackgroundTaskInvalid;
    NSLog(@"Push token received, probably!");
}

推荐答案

我没有得到任何解决方案,但我还是设法通过了我的应用程序的要求,这个问题并不是什么大问题.我确实有一种强烈的感觉,iOS 就是这样设计的,如果用户关闭了你的应用程序,那么即使在后台也应该没有任何静默可以启动你的应用程序.当然,我可能是错的,已经很长时间没有使用 iOS 了,我相信很多事情已经改变了.请随时证明我是错的,并描述在 iOS 平台上是否总是有一个合适的解决方案,或者现在有一些新的方法可以解决这个问题.

I did not get any solution but nevertheless I did manage to pass through the requirements with my app and this issue wasn't a big problem. I did get a strong feeling that iOS is designed this way, that if a user shuts down your app, then there should be nothing silent that can start your app even in the background. Of course, I might be wrong, haven't worked with iOS for a long time now, I am sure many things have changed. Please feel free to prove me wrong and describe if there was always an appropriate solution to this present on the iOS platform, or maybe some new ways to solve this problem are available now.

这篇关于应用程序终止和设备重启后 PushKit 通知未到达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆