Nimrod Shai
Nimrod Shai

Reputation: 1179

Remote notification is not called when app is in background

Although this was asked in several places I haven't seen one answer that helped me.

I am trying to get a push notification and tried the following functions:

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

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

The issue:

I am only able to receive the remote notification if the app is in foreground. If it's in background, nothing gets invoked.

I am using iOS8.

The following background modes are checked: "Background fetch","Remote notification"

Can anyone help me with that?

Upvotes: 1

Views: 200

Answers (1)

Aggressor
Aggressor

Reputation: 13551

Its pretty deep in the documenation, but in your JSON payload, you need to set the 'content-available' to 1.

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

If your payload doesn't have an "alert" or "content-available" then you won't get a notification in your app delegate.

Upvotes: 1

Related Questions