PushKit notification not arriving after application kill AND device reboot

自古美人都是妖i 提交于 2021-02-07 09:29:01

问题


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.

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.

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:

  • Voice over IP
  • Remote notifications

here's my code snippet:

- (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!");
}

回答1:


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.



来源:https://stackoverflow.com/questions/31706942/pushkit-notification-not-arriving-after-application-kill-and-device-reboot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!