ios - Apple 的静默推送通知能否在后台启动我的应用程序?

标签 ios apple-push-notifications

根据 Apple 的文档,我可以通过在 aps 有效负载字典中添加 "content-available"= 1 键值来注册静默通知。我希望我的应用程序在静默通知到达时在后台唤醒。我在我的 info.plist 中将 App downloads content in response to push notifications 值设置为 Required background modes

这是我的有效负载字典

{"aps":
      {
       "alert":"Notification alert","badge":1,"sound":"default","content-available":1
      }
}

我在 -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler 中收到回调 当我的应用程序处于后台时。但我的问题是,当我们的应用程序处于终止状态时,我们能否获得对此方法或任何其他方法的回调?

我不希望我的应用用户看到通知,但我希望我的应用通过静默通知在后台唤醒它来执行某些任务。

如有任何建议,我们将不胜感激。

最佳答案

当设备收到设置了 content-available 的推送消息时,Apple 会在后台启动您的应用。用户不会意识到这一点。 From the docs :

content-available: Provide this key with a value of 1 to indicate that new content is available. Including this key and value means that when your app is launched in the background or resumed, -application:didReceiveRemoteNotification:fetchCompletionHandler: is called.

同样来自 docs

didReceiveRemoteNotification: However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again.

关于ios - Apple 的静默推送通知能否在后台启动我的应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34291002/

相关文章:

ios - Xcode - Podfile 没有正确安装 swiftvalidator

ios - 如果从 App Delegate 启动,则 ViewController 显示没有导航栏

ios - 适用于应用程序轮询服务器的iOS7本地通知,用于在后台运行的新关注数据

ios - 如何使用 javapns 将自定义属性添加到 ios 推送通知负载?

ios - 如何快速获取json对象的数组

ios - 如何在 swift 3.0 中更改所选日期文本颜色

iphone - 如何在 iPhone 中获取推送通知

javascript - Azure移动服务成功回调 `push.apns.send`

ios - 我如何观察 ReactiveSwift 中 UIControl 子类的变化?

ios - 为什么 weak_table_t 在 Objective-C 运行时是 SideTable 的成员?