0

I use push notification in my app ,It is work fine but I want to receive notification if my app in background but method didReceiveRemoteNotification not called
I mad that
1- enable Background Mod
2- check remote notification
3- put content_available = true in data payload
and also when I test it from fcm dashboard not work ,
Please can anyone help me , Thanks.

Hosny
  • 821
  • 1
  • 13
  • 25

3 Answers3

0

If you're testing on iOS 10, content_available must be in JSON value of notification key, not in data key. Although for iOS <= iOS 9, content_available can be in JSON value of data or notification.

Ravi Sisodia
  • 776
  • 1
  • 5
  • 20
  • Hi,I found the reason that mad notification not work in background is i sent payload with alert key , and when I sent aps just with content_available and sound key then it worked as charm :) , but i think this is not right . – Hosny Oct 07 '16 at 20:35
0

There's a typo in your code. It's not "content_available", the correct key is "content-available". When you send "content-available" = 1, didReceiveRemoteNotification will be called.

S.S.D
  • 1,579
  • 2
  • 12
  • 23
-1

You app needs to handle all the possible push notification delivery states:

Your app was just launched Your app was just brought from background to foreground Your app was already running in the foreground You do not get to choose at delivery time what presentation method is used to present the push notification, that is encoded in the notification itself (optional alert, badge number, sound). But since you presumably are in control of both the app and the payload of the push notification, you can specify in the payload whether or not there was an alert view and message already presented to the user. Only in the case of the app is already running in the foreground do you know that the user did not just launch your app through an alert or regularly from the home screen.

You can tell whether your app was just brought to the foreground or not in didReceiveRemoteNotification using this bit of code:

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

{
    if ( application.applicationState == UIApplicationStateActive )
    // app was already in the foreground
    else
    // app was just brought from background to foreground
    ...
}

for further reference. Please check

didReceiveRemoteNotification when in background

Community
  • 1
  • 1
  • Hi , Thanks for your answer but as I said the notification work fine but when app is in background didReceiveRemoteNotification not called but after click notification it is called why ?? – Hosny Sep 25 '16 at 15:23
  • Hi, its obvious that as your app is not active, until user click on notification to move the app from background or foreground state to active state. didReceiveRemoteNotification will not be called. – Mohammed Noman Siddiqui Sep 26 '16 at 07:02