I am working on a app, where I need to send a push notification to the app to start processing data as needed.

How do I send a push notification to the device so that instead of showing the alert message, the notification is forwarded to the app - whether the app is in the foreground or background..

I did implement the delegate method :

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler

however this is called only when the app is in the foreground. When the app is in the background the notification shows up on the notification center.

Please advice.

有帮助吗?

解决方案

To make this works you need to do few step:

  • set background mode remote-notification

  • implement application:didReceiveRemoteNotification:fetchCompletionHandler: method in app delegate

  • and make sure push notification payload contains key "content-available" : 1

related docs:

App States and Multitasking

Local and Push Notifications in Depth

其他提示

Is your application using a backend? An example would be Parse or another to store your data.

Parse, for example, allows you to add push notifications that can be customized and changed to get the most out of your application.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top