3

I want to send silent notifications to my iOS app, for which i have implemented FCM into it. while app is in background, i need to perform some operation when app gets the notification from the FCM .

for that ,execution process will enter into the method called

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


but problem is that, it does not enter into this method until user taps on the notification .

As per (FCM documents) , if we want to wake up our app in background then we have to pass content_available parameter with key value true . but when i am sending this information through your FCM Compose message console in custom data, our app is not waking up nor getting activated in background, until user taps on the notifications. I guess the notifications which all i am receiving are normal notifications, not silent one . so FCM implementation and sending notification is working perfectly it seems.

i have followed all the FCM documents given and referred almost all possible connected stackoverflow solutions . even i have followed apple documents for sending remote notifications . and lastly i am sending "content_available" : true through FCM message console. but it is not becoming silent notification and i am receiving notification as normal notification which user has to tap on, to enter into the method didReceiveRemoteNotification.

i have referred many links like these here, here, & here

is it even possible through FCM to receive notifications in backgrounds (like silent notifications) or not ? or any other way to implement it ?

Nate
  • 31,017
  • 13
  • 83
  • 207
Moxarth
  • 303
  • 4
  • 13
  • `content_available` is a parameter that should be outside both `notification` and `data` in your payload. Putting any key-value pair in the custom data puts it inside the `data` message payload. – AL. Dec 13 '17 at 01:15
  • okk , let me try out that . – Moxarth Dec 13 '17 at 05:28
  • 1
    i have contacted firebase-support and they said that " sending silent notification in the Notifications console is not possible. Its primary use is to send campaigns that will be displayed to users. If you wish to send silent notification, you'll need to use FCM API instead. " . so how to use that FCM API ? do you know how to do that ? – Moxarth Dec 13 '17 at 07:09
  • You could try using Postman -- see my answer [here](https://stackoverflow.com/a/45310143/4625829) – AL. Dec 14 '17 at 04:54
  • 1
    i did what you have said but i am getting this type of format userInfo->{ alert = { body = "noti body"; title = "noti title"; }; } ... and still i did not get notification as silent one , while app is in background state . – Moxarth Dec 14 '17 at 10:31
  • { "to":"AAAA ..... .... ..... .....", "priority": "normal", "content_available": true, "notification":{ "requesttype":"ring" } } ..... like this we have solved it . thanks for your guidance . we have been stuck for a long long time . – Moxarth Dec 14 '17 at 10:52

1 Answers1

4

i have got the solution for this . just follow this link and its answer .

and enter the json body like this in postman

{
    "to":"eEBrg.... .... .... .... (FCM Token)",
    "priority": "normal",
    "content_available": true,
    "notification":{
 (do not send body here if you want to send the silent notification)
      "requesttype":"ring" // optional
    }   
}

... and your app will wake up in background and will enter into the method didReceiveRemoteNotification .

Moxarth
  • 303
  • 4
  • 13
  • 1
    I have checked this now , if the App is in background it will never wake up automatically . Only if the user gets the app to foreground then all the notification will start appearing inside didReceiveRemoteNotification – Max Apr 11 '18 at 07:57