My app implements GCM, but the notifications only receive by topics and not by specific token app.
This it's a example:
{
"registration_ids" : ["dh"],
"content_available" : true,
"priority": "high",
"notification" : {
"body" : "Winter is coming!",
"title" : "John Snow"
}
}
The response:
{
"multicast_id":000000,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results": [
{
"error": "InternalServerError"
}
]
}
But the device receives the notifications while they was sent by topics.
2015-09-16 22:54:50.931 ExamplePush[1622:379584] Notification received:
{
"collapse_key" = "do_not_collapse";
from = "/topics/global";
message = "{\"id\":102}";
}
Please see this:
Postman 1
Postman 2
You need to add parameter "to" into your request in order to get notification and look at the gcm document as well for more information.
{
"to" : " mh7PX-ODCIE:APA91bEdBMCxTJ45SEcCWRyCfzkkZ74YnJl0q0-J8zgIdcZySgR3wu46RXwBHmSzscI6AuI9inYT145C5j30UPMD7soDKRgTGbrcdgZPUahm_Ik-oIUKoUSLLzGNXBeNqnWKDhpHlBfn",
"content_available" : true,
"priority": "high",
"notification" : {
"body" : "Winter is coming!",
"title" : "John Snow"
}
}
are you checking on postman
If not then try to check in postman
By this url and append the parameters.
https://gcm-http.googleapis.com/gcm/send
set the header also with your api key of gcm.
Related
I am working with xamarin ios and firebase cloud messaging.
This is my fcm request body.
{
"registration_ids": ["token1","token2"],
"notification": {
"sound": "default",
"body": "test body",
"title": "test with notification",
"content_available": true,
"priority": "high"
},
"data": {
"notificationType" : "notification"
}
}
I want to retrieve "notificationType" in DidReceiveRemoteNotification method.
This is my method :
[Export("application:didReceiveRemoteNotification:fetchCompletionHandler:")]
[ObjCRuntime.Introduced(ObjCRuntime.PlatformName.TvOS, 10, 0, ObjCRuntime.PlatformArchitecture.All, null)]
[ObjCRuntime.Introduced(ObjCRuntime.PlatformName.iOS, 7, 0, ObjCRuntime.PlatformArchitecture.All, null)]
public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
{
UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
NSDictionary data = userInfo.ObjectForKey(new NSString("data")) as NSDictionary;
string notificationType = Convert.ToString(data[new NSString("notificationType")] as NSString);
}
Let me know what I need to change here?
Thanks.
I had a problem with sending push notification from FCM server. Previously, we use APNS for this purpose, my server and clients create payload like this. And it worked very well.
{
"data": {
"image": "https://premierleague-static-files.s3.amazonaws.com/premierleague/photo/2018/09/24/0e228e97-1644-4fcf-bc18-d7223d8f398f/DreamTeamGW6.png",
"link":"https://stackoverflow.com/"
},
"aps": {
"alert": "This is me",
"sound": "default",
"mutable-content": 1
},
"contentId": "123456"
}
Now, we turn to use FCM as replacement of APNS, as you've known, FCM server will receive the message, convert it to APNS format then send it to APNS server, the APNS server will send the converted message to clients. But first, I have to follow its payload's format like this.
{
"notification": {
"body": "This is me",
"badge": 1,
"sound": "default",
"mutable-content": 1
},
"delay_while_idle": false,
"data": {
"data": {
"image": "https://premierleague-static-files.s3.amazonaws.com/premierleague/photo/2018/09/24/0e228e97-1644-4fcf-bc18-d7223d8f398f/DreamTeamGW6.png",
"link":"https://stackoverflow.com/"
},
"contentId": "123456"
},
"time_to_live": 10
}
And the converted message from FCM to APNS was not I desired.
{
"data": "{\"image\":\"https:\\\/\\\/premierleague-static-files.s3.amazonaws.com\\\/premierleague\\\/photo\\\/2018\\\/09\\\/24\\\/0e228e97-1644-4fcf-bc18-d7223d8f398f\\\/DreamTeamGW6.png\",\"link\":\"https:\\\/\\\/stackoverflow.com/\\\/\"}",
"aps": {
"alert": "This is me",
"sound": "default",
"mutable-content": 1
},
"contentId": "123456"
}
As you see, the value of "data" key was not JSONObject like before, it became a string. My question is: How can I make the FCM server understand that the sub "data" object inside main "data" is a JSONObject, not a string when it convert my message to APNS's payload?
Thank you!
In your FCM payload (reference for the FCM payload parameters here):
badge should be String
mutable_content should be outside notification
delay_while_idle is deprecated
data messages can only hold key-value pairs. You're passing a (data) JSON object which is not expected to work.
The fastest way I could think of in order to make this work is have the contents of your data JSON object outside (i.e. same level as the contentId and then format your FCM payload like so:
{
"mutable-content": 1
"notification": {
"body": "This is me",
"badge": 1,
"sound": "default"
},
"data": {
"image": "https://premierleague-static-files.s3.amazonaws.com/premierleague/photo/2018/09/24/0e228e97-1644-4fcf-bc18-d7223d8f398f/DreamTeamGW6.png",
"link":"https://stackoverflow.com/",
"contentId": "123456"
},
"time_to_live": 10
}
But depending on your client side code, this couldn't work, but I hope you get the gist. Cheers!
I am using Firebase push notifications in my iOS Application. Although I am able to send the notification by sending below payload, it doesn't play a sound when received.
{
"to": "myToken",
"notification": {
"body": "test",
"title": "test"
},
"priority": "high"
"sound": "default"
}
If I send the test message from console, it works well and plays notification sound. Note:
My Authorization code is correct
I am sending http request to https://fcm.googleapis.com/fcm/send
I have tested it on IPhone 4 , IPhone 6 and IPhone 6S, All recieve
notifications without sound
your JSON "sound" : "default" should be inside the "notification" key not in the root of the JSON. This JSON should work.
{
"to": "myToken",
"notification": {
"body": "test",
"title": "test",
"sound": "default"
},
"priority": "high"
}
When using the FCM admin SDK, you have to specify sounds separately for Android and Apple devices:
let message = {
notification: {
'body': 'This is the message the user sees',
},
data: {
'param1': 'specify some extra data here',
},
// Apple specific settings
apns: {
headers: {
'apns-priority': '10',
},
payload: {
aps: {
sound: 'default',
}
},
},
android: {
priority: 'high',
notification: {
sound: 'default',
}
},
token: 'target FCM token goes here',
};
(Note: I've only tested the Apple settings thus far)
payload = {
notification:{
title: 'SOLO has been changed by an administrator',
body: 'Administrator changed your SOLO schedule',
},
android: {
},
apns: {
headers:{
"apns-collapse-id": "solo_changed_administrator",
"content-available": "1",
"apns-priority": "10",
},
payload:{
aps:{
sound: 'default',
badge: 12213123223
}
}
},
data:{
type: 'type'
}
}
https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?authuser=0#ApnsConfig
I had the same problem. When notifications come through FCM to iOS not working sounds or vibrations. Here I followed this link: https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html#//apple_ref/doc/uid/TP40008194-CH17-SW1
And finally went successful. I created my apple notification as an alert in my payload and it works for me. Here is my JSON below to get some idea about my solution.
"apns": {
"payload": {
"aps" : {
"alert" : {
"body": "Notification body",
"title": "Notification title"
},
"badge" : 2,
"sound" : "default"
}
}
}
Note: Please put this "apns" key in the relevant place of your message request. I was using REST call for requesting message.
Please refer the following link to get a good idea of how to send a notification message with platform-specific delivery options.
Link: https://firebase.google.com/docs/cloud-messaging/concept-options#example-notification-message-with-platform-specific-delivery-options
iOS Push notification through AWS SNS.
Payload getting displayed inside iOS devices notification panel instead of message.
ex :
{
"default": "Sample message",
"APNS": {
"aps": {
"alert": {
"body": "You have new message",
"title": "Sample message"
}
}
}
}
The problem is you kept aps inside APNS.
As per the apple documentation, the payload should be like this,
{
"aps" : {
"alert" : {
"title" : "Game Request",
"body" : "Bob wants to play poker",
"action-loc-key" : "PLAY"
},
"badge" : 5
},
"acme1" : "bar",
"acme2" : [ "bang", "whiz" ]
}
Note: "aps" should be available directly in the keys, you should not enclose it inside other values.
Documentation: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/TheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH107-SW1),
I am trying to send a push notification through FCM, but the response sent to the phone is weird and does not include aps.
I send:
{ "notification" : {
"title" : "this is title",
"body" : "this is body",
"sound" : "defadult"
},
"data": {
"score": "5x1",
"time": "15:10"
},
"time_to_live" : 3000,
"priority" : "high",
"content_available": true,
"to" : "<fcm access token>"
}
and I get the following on the phone:
%# [notification: {
body = "this is body";
e = 1;
sound = default;
sound2 = defadult;
title = "this is title";
}, collapse_key: <bundle-url>, score: 5x1, time: 15:10, from: 844316448558]
This had been working for a while but suddenly broke. Does anyone else experience this?