0
votes

I have a problem with receiving push notifications when app is in background or it was killed. When app is in foreground, didReceiveRemoteNotification: is called and app gets the push notification. However when app is in background or it was killed, and push notification arrives to the device, ONLY sound can be heard but banner is not showed, even if apps has set UIUserNotificationSettings for badge, sound and alert (in 'Settings' app everything is enabled).

If I'm not wrong didReceiveRemoteNotification: works both for foreground and background states, if app is not running at all, and user touch the notification's banner, the notifications info will be received in didFinishLaunchingWithOptions:.

So the question is: why didReceiveRemoteNotification: is not working in background AND why notification's banner not showed when app is in background ?

4
not relevant directly to your question but I'm having problem with push notifications since apple gave up on ssl 3 can you post your server side code (if you are using django or python), thanksliv a

4 Answers

0
votes

About receiving in the background: Make sure you have the content-available field in your payload:

{
"alert":"",
"badge":"0",
"content-available":"1",
"sound":""
}

For more info you can check out this post: Apple Push Notification in Background Issue

0
votes

didReceiveRemoteNotification: method works only when your app is in foreground, if your app is not running then you need to check didFinishLaunchingWithOption like

     if (launchOptions) { //launchOptions is not nil
    NSDictionary *userInfo = [launchOptions valueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];

  NSLog(@"%@",userInfo);
 }
0
votes

1) why didReceiveRemoteNotification: is not working in background

It's ok such behaviour, didReceiveRemoteNotification: is not called in background. Instead of this, in didFinishLaunchingWithOptions:, should be checked if app was started because of push notification arrival:

NSDictionary *aPushNotification = [launchOptions valueForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
if(aPushNotification) {
    // Do something with push's payload
}

2) why notification's banner not showed when app is in background

This happened because 'alert' field was missing from push notification's payload

0
votes

I faced similar problem so i uses .. Receivepushnotifications

[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

and also check your payload properly it should contain alert if you wana present it when push notification arrives .