iOS 中的远程推送通知

Remote Push Notifications in iOS

有没有办法让应用程序在收到远程推送通知时在后台唤醒并阻止 iOS 7/8 显示通知警报(类似于 Android 中可以使用WakefulBroadcastReceiverLocalBroadcastManager)?我希望 didReceiveRemoteNotification: fetchCompletionHandler 能够实现这一点,但看起来它并不是为此目的而设计的。对于实时系统,服务器有时必须向应用程序推送多个通知,我想防止多个警报出现在用户的设备上,因为只有最后一个很重要。我当然可以处理服务器端,但更愿意在应用程序中实现该逻辑。

不要在通知对象中发送 "alert" 键。 content-available 标记为 1 用于后台通知。如果您想在某个时候向用户显示警报,您可以使用 "extra" 收到的通知字典中的内容来显示警报。

这是可能的,didReceiveRemoteNotification:fetchCompletionHandler 正是为您所指的内容而设计的。

The aps dictionary can also contain the content-available property. The content-available property with a value of 1 lets the remote notification act as a “silent” notification. When a silent notification arrives, iOS wakes up your app in the background so that you can get new data from your server or do background information processing. Users aren’t told about the new or changed information that results from a silent notification, but they can find out about it the next time they open your app.

更多信息在这里:

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html