简体   繁体   中英

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 )? I was hopping that didReceiveRemoteNotification: fetchCompletionHandler will allow to accomplish that, but looks like it is not designed for that purpose. 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. 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.

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.

More information here:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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