即使在应用程序终止后也能获得 Apple 的远程推送通知 [英] Get Apple's remote push notifications even after app terminates

查看:28
本文介绍了即使在应用程序终止后也能获得 Apple 的远程推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 iOS 应用程序,它以特定的时间间隔接收苹果的远程推送通知.当应用程序处于活动状态以及应用程序在后台时,都会成功接收通知.但是当应用从应用切换器/码头终止时,直到应用再次启动时才会收到通知.

I am developing an iOS app which receives apple's remote push notifications at a particular time interval. The notifications are received successfully when app is active as well as when app is in background. But when app is terminated from app switcher/dock, notifications are not received until the app is started again.

我尝试了以下代码来使应用程序在后台保持活动状态.在 applicationWillTerminate: 方法中实现了相同的代码,但它不起作用.

I have tried following code to keep app alive in background. This same code is implemented in applicationWillTerminate: method, but it did not work.

__block UIBackgroundTaskIdentifier bgTask ;
    UIApplication  *app = [UIApplication sharedApplication];
    bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
        [app endBackgroundTask:bgTask];
        [app enabledRemoteNotificationTypes];
        bgTask = UIBackgroundTaskInvalid;
    }];

应用终止后接收通知的最佳方式是什么?

What is the perfect way of receiving notifications even after app is terminated?

推荐答案

如果您在应用切换器中主动停止应用,它将停止接收任何推送通知.

If you actively stop the app in the app switcher it stops receiving any push notifications.

这是 Apple 工程师在开发者论坛中所说的预期行为.

This is an intended behaviour as stated by Apple engineers in the developer forums.

这篇关于即使在应用程序终止后也能获得 Apple 的远程推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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