Push notifications are not working in background via FCM in iOS - ios

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

Related

Getting silent notification values when app starts

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.

didReceiveRemoteNotification not called, When app is killed

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"
}
}

Push notification not receive with content_available

I'm working with firebase to add push notification feature to an app, everything is fine with the push notification it self but in some state of the app the push notification is not receive.
Foreground / Background:
{
"data":{
"title": "title",
"message": "message"
},
"content_available":true,
"priority":"high",
"registration_ids":[
""
]
}
The problem comes when the app is killed by the user, I send the same http request but the app didn't receive the remote notification.
I was testing with the console on firebase and when the app is killed the notification it's receive but I couldn't replicate the console request to http request
this is the content of notification when I made it through firebase console
[
"google.c.a.c_l": label optional,
"google.c.a.e": 1,
"google.c.a.ts": IntValue,
"google.c.a.udt": 0,
"gcm.n.e": 1,
"aps": {
alert = {
body = mensaje;
title = title;
};
},
"google.c.a.c_id": IntValue,
"gcm.message_id": 0:1502103735577088%9218dc2f9218dc2f
]
This is how iOS works, basically. When your app is killed by the user, it no longer receives background notifications.
Here's a somewhat-old-but-still-accurate link with some more detailed information: http://samwize.com/2015/08/07/how-to-handle-remote-notification-with-background-mode-enabled/

AWS : Play Custom Sound When Push Messages are received

I have implemented Amazon Web Service(AWS) for notification messages in my app, I am able to send message from Amazon SNS Server successfully.
Now i want to implement default/custom sound, when any messages are received from AWS.
In Amazon SNS Server there are two options fro sending pus messages, those are Raw and JSON. I am using Raw Message Format.
{
"aps":{
"badge":0,
"alert":"APNS test",
"sound":"default"
},
}
by above format i m getting same format as push notification in my app.
If i use JSON Message Format
I m getting in Amazon SNS Page that -
Invalid parameter: Message Structure - JSON message body failed to
parse (Service: AmazonSNS; Status Code: 400; Error Code:
InvalidParameter; Request ID: b34a
Any One could tell tell how to send sound default/custom by using AWS Notification.
Try as bellow
Please make sure to change the JSON according to your need
{
"aps" : {
"category" : "NEW_MESSAGE_CATEGORY"
"alert" : {
"body" : "Acme message received from Johnny Appleseed",
"action-loc-key" : "VIEW"
},
"badge" : 3,
"sound" : "chime.aiff"
},
"acme-account" : "jane.appleseed#apple.com",
"acme-message" : "message123456"
}

GCM (Google Cloud Messaging) push notification from python app server to iOS app

I'm trying to send push notifications to my iOS app with GCM. I tried to follow the (Google GCM) and (GCMServerDemo) for my app but I only can receive the notification printed on the xcode output: [body: hello, it's me, sound: default, collapse_key: do_not_collapse, badge: 2, from: 629354528047] but nothing pop out on my testing phone. My server running on python and I have it implemented as:
from gcm import *
gcm= GCM("123...")
DEV_TOKEN = "l0NOTncXJXQ:APA91bGPVHxvF-PCL-PPNic6zhfnpv0aAe5KhvoYOOF_HfLZlCAquMGQb196J5_4zUEzWEirSOWP86d-n4-DJws4nPs5ZXR1c9UOQOPPuuCAjXFz2VIZ-5_SRz8G6D_MzKHv1W7yRrmZ"
reg_ids = [DEV_TOKEN]
notification = {"body": "hello, it's me", "sound": "default", "badge": 2}
response=gcm.json_request(registration_ids=reg_ids, data=notification)
print(response)
My AppDelegate on my app client to detect notification: http://swiftstub.com/621889661/
My ViewController: http://swiftstub.com/89730359
I want my client app receive the notification both when the app is active and when the screen is off (but right now I only can receive the message sent on my server in the xcode output screen, as [body: hello, it's me, sound: default, collapse_key: do_not_collapse, badge: 2, from: 629354528047])
I guess there is a problem when I parse the received message. Can anyone help me to fix it? Thank you.
This is what the gcm payload should look like if all you want to do is display a message to the user:
{
"to":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification":{
"body":"This text message will be seen by the user",
"badge": 2,
"sound": "default"
}
}
It will only be visible by default when the app is not in the foreground. When it is, you need to read the message in your AppDelegate's didReceiveRemoteNotification method, and show it to the user yourself.
Edit:
Instead of using gcm.plaintext_request(registration_id=reg_id,data = data)
you might want to try this:
notification = {'body': "hello, it's me", "sound": "default", "badge": 2}
DEV_TOKEN = '**********************************'
reg_ids = [DEV_TOKEN]
response = gcm.json_request(registration_ids=reg_ids, notification=notification)
notification should be outside the data key

Resources