简体   繁体   English

iOS中的远程推送通知

[英]Remote Push Notifications in iOS

Is there a way for the app to wake up in background when remote push notification received and prevent iOS 7/8 from displaying notification alert (similar to what can be done in Android using WakefulBroadcastReceiver and LocalBroadcastManager )? 有没有一种方法可以让应用在收到远程推送通知时在后台唤醒,并阻止iOS 7/8显示通知警报(类似于在Android中使用WakefulBroadcastReceiverLocalBroadcastManager )? I was hopping that didReceiveRemoteNotification: fetchCompletionHandler will allow to accomplish that, but looks like it is not designed for that purpose. 我当时希望didReceiveRemoteNotification: fetchCompletionHandler可以完成该任务,但看起来它并非为此目的而设计的。 With the real-time systems, servers sometimes have to push multiple notifications to the app and I want to prevent multiple alerts appearing on a user's device, since only the last one matters. 对于实时系统,服务器有时必须将多个通知推送到应用程序,并且我想防止在用户设备上出现多个警报,因为只有最后一个才很重要。 Of course I can handle that server side, but would prefer implement that logic in the app. 当然,我可以处理该服务器端,但希望在应用程序中实现该逻辑。

Don't send "alert" key in notification object. 不要在通知对象中发送“警报”键。 And content-available flag as 1 for background notifications. 内容通知标志为1表示背景通知。 You can manage to show alert using content in "extra" dictionary of notification you receive if you want to show alert to user at some point. 如果您希望在某个时候向用户显示警报,则可以使用收到的“额外”通知字典中的内容来显示警报。

This is possible and didReceiveRemoteNotification:fetchCompletionHandler is designed for exactly what you're referring to. 这是可行的,并且didReceiveRemoteNotification:fetchCompletionHandler专为您所指的内容而设计。

The aps dictionary can also contain the content-available property. aps词典也可以包含content-available属性。 The content-available property with a value of 1 lets the remote notification act as a “silent” notification. 值为1的内容可用属性使远程通知充当“静默”通知。 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. 当收到静默通知时,iOS会在后台唤醒您的应用程序,以便您可以从服务器获取新数据或进行后台信息处理。 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. 不会通知用户有关静默通知产生的新信息或更改信息,但是下次打开应用程序时,他们可以找到有关信息。

More information here: 此处有更多信息:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM