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
Related
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'm getting follow message when I receive Push Notification and the same JSON is displayed to user too. I want only the Data to be displayed in the body when user receives the push notification rather than displaying the whole JSON.
under aps["alert"] I get this
{
\"Type\":\"TestType\",
\"NotificationId\":\"40\",
\"ImageUrl\":\"\",
\"UserId\":1,
\"Data\":\"Testing Push Notification\"
}
How to display Data in the message body of Push Notification.
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
if(application.applicationState == UIApplicationState.Active) {
if let alertInfo = userInfo["aps"]?["alert"] as? Dictionary<String,String>{
if let title = alertInfo["Data"]{
}
}
}
}
please try to send push notification flowing format and if application staying in background then automatic showing body message :
[aps: {
alert = {
body = "Testing Push Notification";
title = "New Message";
NotificationId= "536"
};
sound = default;
}]
Update correct format For example
{
"aps": {
"alert": "Hello World",
"sound": "default"
},
"Person": {
"Address": "this is a test address",
"Name": "First Name",
"Number": "023232323233"
}
}
iOS Push Notification custom format
The keys in aps are pre-defined by apple. But you can send your custom
keys outside aps as shown below
{
"aps": {
"alert": {
"title": "Hey!🙂 Checkout my custom notification",
"subtitle": "Custom notification subtitle",
"body": "Description of custom notification"
},
"sound": "default",
"category": "CustomPush",
"badge": 1,
"mutable-content": 1
},
"Employee": {
"Name": "John Doe",
"Designation": "Manager"
}
}
Where Employee is custom key where you can set your own data
as required
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?
Apple's push notification server version 2 drops this message:
{
"aps": {
"badge": 1,
"alert": {
"loc-key": "New message from %#",
"loc-args": ["joe"]
},
"sound": "default"
},
"arg": "value"
}
But it delivers this message:
{
"aps": {
"badge": 1,
"alert": {
"loc-key": "New message from",
"loc-args": ["joe"]
},
"sound": "default"
},
"arg": "value"
}
Not only is the message not delivered but no http2 response is received and the connection is not disconnected.
I'm testing with apple's development service.
The app doesn't have a Localizable.strings file for the language (english).
How do I fix this?
It seems that as soon as a 'loc-key' contains a '%#' it can't be localized.
Moving the %# from the key into a value in Localization.strings works.