iOS Push notification through AWS SNS - ios

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),

Related

Displaying Message Body in Push Notification

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

FCM Notification in iOS doesn't play sound when received

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

Firebase Cloud Messing possible bug?

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 dropping a message that seems valid

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.

iOS app receives GCM notifications only by topics

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.

Resources