Amazon SNS invalid message structure for APNS - ios

I've implemented Amazon SNS for push notifications.
I'm sending json in the following structure:
{
"aps":{
"alert":{
"loc-args":["ARGS"],
"loc-key":"KEY",
}
"sound":"default"
}
}
But on iOS client I'm receiving it as escaped string and everything from my message is inside "alert" key
[AnyHashable("aps"): {
alert = "{\"aps\":{\"alert\":{\"loc-args\":[\"ARGS\"],\"loc-key\":\"KEY\"},\"sound\":\"default\"}";
}]
I've also tried different formats from here http://docs.aws.amazon.com/sns/latest/dg/mobile-push-send-custommessage.html but every-time I'm receiving the same escaped string.
Does anyone had the same problem?

So the problem was in publishRequest.setMessageStructure("json"); flag.
I've missed it.
Also notification should be sent in the following format:
{"APNS_SANDBOX":"{\"aps\":{\"alert\":{\"loc-args\":[\"ARGS\"],\"loc-key\":\"KEY\"},\"sound\":\"default\"}}

Related

FCM Throwing invalid-argument for IOS notifications

My project had working notifications previously and I can't trace any changes to the payload I've been sending. I've referenced the docs and can't see any issues with my payload. The exact error I am getting is
Request contains an invalid argument
let payload = {
token : oUser.devicetoken,
data : {
referenceid : chatid,
referencetype : 'chat',
referencename : oSender.displayname,
receiverid : userid,
type : 'message',
notificationid : res,
title : title,
body : `${oSender.displayname} : ${body}`
},
android : {
priority : 'high'
},
apns : {
payload : {
aps : {
'content-available' : 1
}
},
headers : {
'apns-push-type' : 'background',
'apns-priority' : '5',
'apns-topic' : 'llc.attebyte.partyme'
}
}
};
My current payload:
After taking a fresh look at the Apple docs for notifications I noticed that I should be using content-available. I had previously been using contentAvailable: true (and it was working). Neither one is working anymore.
There are multiple questions regarding this problem already. This one being the best I've found: firebase cloud messaging Request contains an invalid argument
I verified that the token is correct by sending the device a test notification from the firebase console. I don't think I should be hitting the size limit of 4kb, the message I am sending for testing is something along the lines of 'test' or 'hello' (also the issue is IOS specifi). I've also verified that the headers I am sending are current with the Apple docs.
I can't figure out any differences that would cause notifications to stop working within the last week or so. I know they were working then and I've gone through my Github history to verify the payload hasn't changed (besides my change to content-available I made today while testing.)
While Google takes its time to fix this, we could successfully send silent notifications using the legacy app server protocols:
https://firebase.google.com/docs/cloud-messaging/send-message#send-messages-using-the-legacy-app-server-protocols
The endpoint we are using is https://fcm.googleapis.com/fcm/send.
Here you can find the message structure (note that is quite different from the current API):
https://firebase.google.com/docs/cloud-messaging/http-server-ref
And here how to authorize the requests:
https://firebase.google.com/docs/cloud-messaging/auth-server#authorize-http-requests
Hope it helps while we wait for a definitive fix.

Not getting notifications in receiver side

I am using two firebase database projects. I have to send notifications from one database(Project-A) to another database(Project-B). I am sending notifications through API calls in cloud functions( in Project-A) and have to receive in IOS device ( from Project-B). I am sending the device token which is generated by using Project-A's SenderId through API call and saving that token in Project-A's database. In Project-A, using cloud function I am sending a notification to the IOS device in Project-B. In Project-A's firebase console it showing the notification is successfully sent, but in the receiver side, I am not getting any notification.
Payload:
let payload = {
notification: {
title: "Notification Alert",
body: "Notification Body",
sound: "default",
},
'data':{// these is the data it calls in the messagereceived method
'SenderID':senderauthid,
'ReceiverId':receiverauthid,
'SenderPhoneNumber':String(senderphonenumber),
'SenderName':Sendertotalname,
'flag':"3",
}
};//payload
return admin.messaging().sendToDevice(RegisterationTokens, payload).then((response)=> {
console.info("Successfully sent notification")
return res.status(200).json({Token : "Successfully sent notification"});
}).catch(function(error) {
console.warn("Error sending notification " , error)
});//end of notification
On successful notification message sent, I am receiving an error message stating that
errorInfo:
{ code: 'messaging/invalid-apns-credentials',
message: 'A message targeted to an iOS device could not be sent because the required APNs SSL certificate was not uploaded or has expired. Check the validity of your development and production certificates.' },
codePrefix: 'messaging' }
I have already added "APNs Auth Keys" in "APNs Authentication Key" section in firebase console. Do I have to make any changes?

Swift - Push Notification JSON format

Please let me ask about Push Notification issue here.
Our server sent out the data in JSON format like this
{
"notification":
{
"body”:”Test Push Notification (42)”,
"node":"1233837”,
"content-available":"1"
},
"priority":"high"
}
The process of sending out push notification to our app is
We sent out notification from our sever to GCM
From GCM, sending out to APNS.
But when we receive push notification in our app, the format is totally changed (as shown in attached image).
If you face with this kinda issue before, could you share with how to solve it, please?
Or is there any way to change in GCM to get normal JSON format?
Try next format to send notification to GCM:
{ "notification": { "body”:”Test Push Notification (42)”, "node":"1233837” }, "priority":10, "content-available":true }
From APNS you app get some like this
{
aps:{
alert:{
*bla bla bla*
},
*bla bla bla*
}}
Just parse it in didReceiveRemoteNotification: method.

Send push notifications to iOS with Amazon SNS and handle them with Localized Formatted Strings

I'm trying to send iOS push notifications from Amazon SNS and i'm able to do it, but i want to use localized formatted string to send the notification and push the message in the right language.
I'm using XCode 7.0.1 and developing with an iPhone 5S, but i think that's not the point.
So this is the message i'm trying to send:
{
"default":"This is the default Message",
"APNS_SANDBOX":"{ "aps" : { "alert" : {
"loc-key" : "GAME_PLAY_REQUEST_FORMAT",
"loc-args" : [ "Jenna", "Frank"]
},"data": { "type": "dashboard", "opponentName":"Juan ","gameCategory":"Multimedia","gameType":"combo","ugid":"123456789" }, "badge" : 9,"sound" :"default"}}"
}
It can be send, but its not changed in the device and the message is "GAME_PLAY_REQUEST_FORMAT", so what i want to be displayed is the value of this key in my Localizable.strings file:
"GAME_PLAY_REQUEST_FORMAT" = "%# and %# have invited you to play";
I've red that you can do it in the apple's documentation (https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW21)
Hope anyone can help.
Thanks
I'll post the answer here so everyone can see it.
#TàTruhoada yes, you need to use loc-keys in the payload. You can see how it works in the following link: Creating the Remote Notification Payload
Use loc-key to pass a key that is defined in your application's Localizable.strings file. The iPhone looks up the key and replaces it with the string found for the current localization.
You can see more information in this link from Erica Sadun: Building Notification Payloads

Trigger.io and Parse channel push notification additional data for deep-linking

I know there is event listener in TriggerIo to catch received push notifications from Parse:
forge.event.messagePushed.addListener(function (msg) {
alert(msg.alert);
});
But the 'msg' object contains only 'alert' and 'sound' keys...
Is there a way to receive at least a channel name to which push notification was sent? I need this to decide which view to open in my app as each channel has it's own destination. And if this is not possible, maybe there is another way to do this?
P.S I suppose it could be done by inserting some kind of 'keyword' into message it self, but I would rather avoid it.
I just realised, that there is a way to send so called JSON payload via Parse push submission form.
{
"alert" : "My message",
"additional" : "data"
}
More info: https://parse.com/questions/json-format-to-send-notification-from-parse

Resources