I have an app implemented with fcm . I can receive push notifications in all cases, that works good. But didReceiveRemoteNotification is not call if app is terminated / kill by user. if app is in background or for-ground it is calling. App is terminated notification is coming, but didReceiveRemoteNotification:fetchCompletionHandler didn't call.
My Question is what is the trigger method app is terminated and a firebase notification received.I used Swift 4.2 and Xcode 10.0. I enable background Modes - Remote notifications from capabilities.
With Firebase I send this JSON:
{
"to": "/topics/group1",
"priority" : "high",
"content-available": true,
"notification" : {
"body" : "Yes you recevied !",
"sound": "default",
"title" : "Notification"
},
"data": {
"type" : "IOS"
}
}
From the Apple docs:
However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again.
You actually can get it round by enabling VoIP background mode, but it will reduce your chances to pass review in the app store.
Your key/value for content-available is incorrect. The key is content_available (underscore, not dash) and the value is a boolean, not string:
{
"to": "/topics/group1",
"priority" : "high",
"content_available": true, // <= CHANGED
"notification" : {
"body" : "Yes you recevied !",
"sound": "default",
"title" : "Notification"
},
"data": {
"type" : "IOS"
}
}
Related
I am trying to implement cache meachanism for FCM on IOS. I am using Xamarin Forms with CrossGeeks FirebasePushNotificationPlugin
Push notification service works fine. I am using payload pattern as below
{
"data": {
"message" : "my_custom_value",
"other_key" : true,
"body":"test"
},
"notification": {
"body" : "hello",
"title": "firebase",
"sound": "default",
"content_available" : true
},
"priority": "high",
"condition": "'general' in topics"
}
Above pattern appears delivered notification as alert on IOS main screen.
I have written a Dependency Service for getting undeleted or unopened accumulated notifications when app starts. Dependency Service include below codes
await UNUserNotificationCenter.Current.GetDeliveredNotificationsAsync();
When I use above payload, I can get accumulated notifications. But when I use payload pattern as below, I can not.
{
"data": {
"message" : "my_custom_value",
"other_key" : true,
"body":"test"
},
"notification": {
"content_available" : true
},
"priority": "high",
"condition": "'general' in topics"
}
Actually I would like to send 2 payload types for every notification for my cache mechanism because of prevent the user's delete action. After that, I would like to show cached notifications without any lost in my app's notification page.
Shortly my question about "I am not getting silent payload values from UNUserNotificationCenter this approach is possible or not?"
Or can I prevent the user's notification delete action from IOS main screen when my app is terminated.
Note: My minimum OS version is 10.0 in info.plist
Thank you in advance.
How can I make the notifications to show in the status bar instead of queuing up and received in the app when brought to the foreground?
I have set up the FCM-account with the APNs, enabled push notification, background fetch and remote notifications.
I've done the equivalent on android where it works as expected.
My message looks like this:
{
"notification": {
"body": "this is a body",
"title": "this is a title",
"content_available": true
},
"priority": "high",
"data": {
"click_action": "FLUTTER_NOTIFICATION_CLICK",
"id": "1",
"status": "done"
},
"to": "TOKEN"
}'
What am I missing?
The notifications appear only when the app is not in foreground. If you want to display them when in foreground, you should implement your custom UI for this.
The app is on both iOS and Android, for this notification to work on both platforms, I removed notification field from notification json payload. But now iOS does not handle this notification when in background.
This one works on iOS but it has notification field which I do not want.
{
"registration_ids": [
"...",
"..."
],
"priority": "high",
"notification": {
"body": "Notification Body.",
"title": "Notification Title"
},
"data": {
"userId": "11111",
"badge": 10
}
}
This one works in android but not working on iOS when in background:
{
"registration_ids": [
"...",
"..."
],
"mutable_content": true,
"content_available": true,
"data": {
"click_action": "AndroidIntent"
"message": "Notification Body",
"myDataField": "11",
"location": "3",
"imageurl": "http://image.com/13fd.png"
}
}
The bottom one does not even enter my Notification Service Extension. How do I make sure my Notification Service Extension is called without adding a notification field on my json?
I have the same thoughts. I was thinking of receiving data from firebase and push local notification with customized title and body with notification service extention. This idea worked fine in foreground by implementing didReceiveRemoteNotification userInfo: in appDelegate to receive userInfo.
But it didn't work in background mode by enabling content_available. you send notification using APN Servers not Fcm Servers relating to firebase docs. I suggest to have a look in content_available and mutable_content
Remove content_available since this is the property to handle silent notifications.
Push notifications are working in foreground but not in the background.
Actually push receives but in the notification area it doesn't show.
Please let me know what could be the issue.
When I debug I found that format is not like APNS push notification.
This is apns format.
"aps" : {
"alert" : {
"title" : "Game Request",
"body" : "Bob wants to play poker",
"action-loc-key" : "PLAY"
},
"badge" : 5
},
And this is what I am getting from FCM
[from: 374675251923, collapse_key: do_not_collapse, payload: {"push_identifier":"share_credits","message":"gopaldevra share 1 credit with you "}]
PUSh PAYLOAD Background [from: 374675251923, collapse_key: do_not_collapse, payload: {"push_identifier":"share_credits","message":"gopaldevra share 1 credit with you "}]
Thanks
i'm a beginner iOS developer (so.. sorry if I made a stupid mistake).
I have succeeded implementing GCM, it's running fine when plugged in (run with XCode). But when I unplug my device from my PC, it stopped prompting the banners.
So, when :
plugged in -> While opening application -> JSON Recieved
plugged in -> While application on background -> Banners Appear
unplugged -> While opening application -> JSON Recieved
unplugged -> While application on background -> Nothing
I use these JSON
{
"content_available":true,
"to" : "l6rofh8dvAc:AP......BVhhXSYc3thtGklEzJzoZFGRMI7lBk4RhmcW",
"message_id": "1",
"notification" :
{
"body" : "helloo!!",
"title" : "GCM",
"icon" : "",
"sound": "default",
"alert":"default",
"badge":"12",
"color": "#03A9F4",
},
"data":
{
"body":"Hello, How are you?",
"title":"Test"
}
}
is my JSON wrong? or is there something that I missed at the XCode? (i followed the sample from
Setting up a GCM Client App on iOS - Sample (with little modification).
You should set the priority of the message as high. The way you're setting it the priority is set to be low and APNS optimizes battery while sending the message and usually takes hours to deliver the message.
Here is what you need your json to be
{
"content_available":true,
"to" : "l6rofh8dvAc:AP......BVhhXSYc3thtGklEzJzoZFGRMI7lBk4RhmcW",
"message_id": "1",
"priority" : "high", # Add this
"notification" :
{
...
},
}
You can read more about setting priority here https://developers.google.com/cloud-messaging/concept-options#setting-the-priority-of-a-message