In the apple documentation for pushes they give the following example payload
{
"aps" : {
"alert" : {
"loc-key" : "GAME_PLAY_REQUEST_FORMAT",
"loc-args" : [ "Jenna", "Frank"]
},
"sound" : "chime.aiff"
},
"acme" : "foo"
}
Described as
The following payload uses the loc-key to specify a localized string
in the app’s Localizable.strings file. That string is displayed as the
message of the alert. The loc-args contains values to substitute into
the string before displaying it.
There is nothing in the "loc-key" or "loc-args" to indicate if this for the title, subtitle or message, so how does the substitution get applied?
How would this payload be extended to apply the same principle to the push alert title, and subtitle, and body, so that all three have their content pulled from the Localizable.strings file?
You can check here
You have loc-key which is the body part, also you have title-loc-key and subtitle-loc-key. If you use these keys once when the messages are received the keys will be changed with the values from Localizable.strings files.
This is an example:
{
"aps" : {
"alert" : {
"loc-key" : "KEY",
"title-loc-key" : "MY_TITLE_KEY",
"subtitle-loc-key" : "MY_SUBTITLE_KEY"
}
}
}
As an additional explanation, loc-args, title-loc-args and subtitle-loc-args are used for such cases:
You want to localize string which says how much points you get in the title of the notification.
you need such row in your strings file:
...
"wining_notification_title_key" = "You won %# points";
...
And then int notification will be:
{
"aps" : {
"alert" : {
"title-loc-key" : "wining_notification_title_key",
"title-loc-args" : ["5"]
}
}
}
Related
I've set up the push notification service extension in xCode.
I've set target Deployment version to 13.0 (app is 13.0 as well)
Info.plist of an extension has correct NSExtensionPrincipalClass
To test, I'm running extension target and selecting app
I'm testing everything on a device that's running iOS 14.2
I've tried following payload:
{
"gcm.message_id" : "XXXXX",
"type" : "XXXXX",
"url" : "XXXXX",
"body" : "XXXX",
"title" : "XXX",
"google.c.a.e" : "XX",
"aps" : {
"mutable-content" : 1,
"alert" : {
"title" : "Test",
"body" : "Test"
},
"category" : "XXXX",
"content-available" : 1
},
"channel_id" : "XXXX"
}
I also tried excluding mutable-content but service extension still didn't get called.
I also tried with simpler payload like this:
{
"aps" : {
"mutable-content" : 1,
"alert" : {
"title" : "Test",
"body" : "Test"
},
"category" : "XXXX",
"content-available" : 1
}
}
No luck here either, both with and without mutable-content
I can always see a push notification as a result of testing but the breakpoint in extension `didReceive` method is not triggered. Also the payload is not modified in any way.
Methods like restating device, restarting macbook and deleting derived data didn't work as well
I managed to solve this buy deselecting Copy only when installing in app target -> Build Phases -> Embed App Extensions
I've implemented handling of remote push notifications in didReceiveRemoteNotification method in AppDelegate.swift and it works except for payloads of following format.
{
"aps" : {
"alert" : {
"loc-key" : "GAME_PLAY_REQUEST_FORMAT",
"loc-args" : [ "Jenna", "This is Message"]
},
"sound" : "chime.aiff"
},
"acme" : "foo"
}
I want to format and show the content of loc-args on the notification alert. I want to extract "Jenna" and "This is Message" from loc-args and display on alert as below in body and title of alert:
New Message from Jenna
This is message
I've been reading tuts but I can't figure out what exactly I've to do to get it done. I want to keep it simple. Any help?
Tx
Solution was Localizable.strings
We are using Firebase for sending remote push notifications, we are in need to grouping received notification like WhatsApp (Ex: 25 new messages received). I have tried it by adding APNs in JSON, but it's not working. Here is my tried code:
{
"to" : "**FCM TOKEN**",
"priority" : "high",
"notification" :
{
"title" : "You have a new message",
"body" : "Test",
"badge" : 1
},
"apns":
{
"headers":
{
"apns-collapse-id":"***APNs ID***"
}
}
}
I'm receiving notification but not able to grouping it.apns-collapse-id which was taken from developer.apple.com.
I am working on FCM, but only below method is getting called.
- (void)applicationReceivedRemoteMessage:(FIRMessagingRemoteMessage *)remoteMessage {
// Print full message
NSLog(#"This is the message whole structure%#", remoteMessage.appData);
NSLocalizedString(#"This is remote message%#", remoteMessage);
NSString * msg = [remoteMessage.appData objectForKey:#"message"];
NSLog(#"msg %#",msg);
[self alertStatus:msg:#"Alert"];
}
And I got full message from server from this above method only. But none of the push notification methods are getting called.I am not receiving any push notification, so I am unable to receive notification in background.
Ask your backend server developer to add notification key in your payload like this
{
"to" : " ...",
"notification" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark",
"icon" : "myicon"
},
"data" : {
"Nick" : "Mario",
"Room" : "PortugalVSDenmark"
}
}
If you want to show notifications for user you should use notification key in your payload.
Reference 1
Reference 2
How to hide push notification in ios? I need to convert push notification to local notification. what should be the structure of payload for this?
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html
You can refer the above link to Know about the payload of push notification.
For not showing push notification you need to pass the payload without alert. If you want a silent notification set Content-available as 1. It'll help.
Eg:
{"aps" : {
"content-available" : 1
},
"YourData":""
}
structure of payload for hide the push notification is..
This Show notification
{
"aps" : {
"alert" : "Message received from Bob"
"badge" : 5,
},
"acme1" : "bar",
"acme2" : [ "bang", "whiz" ]
}
This one hide your notification
{
"aps" : {
"badge" : 5,
},
"acme1" : "bar",
"acme2" : [ "bang", "whiz" ]
}