iOS 10 How to set UNotificationContent threadIdentifier for remote notification - ios

TL;DR: What key needs to be set in the APNs notification payload JSON to correspond to the threadIdentifier property of the UNNotificationContent object? e.g. the "category" key corresponds to the categoryIdentifier property.
iOS 10 introduces the Notification Content Extension allowing us to present a view controller when a notification is expanded.
The view controller that we provide conforms to the UNNotificationContentExtension protocol, that requires us to implement the didReceive(_:) method.
The documentation for this method includes the following paragraph:
This method may be called multiple times while your view controller is visible. Specifically, it is called again when a new notification arrives whose threadIdentifier value matches the thread identifier of the notification already being displayed.
The threadIdentifier property may be set in code for local notifications, but I don't know how to set it for remote notifications that are sent from the server to APNs.
The UNNotificationContent documentation describes the property here: http://developer.apple.com/reference/usernotifications/unnotificationcontent
The following JSON includes the keys I've tried ("thread" and "thread-identifier"):
{
"aps" : {
"alert" : "Hello World!",
"sound" : "default",
"category" : "example-category",
"thread" : "example-thread",
"thread-identifier" : "example-thread-identifier"
}
"custom-field" : "some value",
}
I can't find any documentation from Apple about how to set this. Can anyone help?

I discovered from a contact at Apple that the correct key to populate this property is the "thread-id" key.
So the JSON sent to APNs is as follows:
{
"aps" : {
"alert" : "Hello World!",
"sound" : "default",
"category" : "example-category",
"thread-id" : "my conversation blah blah"
}
"custom-field" : "some value",
}
This populates the threadIdentifier property of the UNNotificationContent object accessible in your Notification Content Extension via notification.request.content.threadIdentifier.
By setting this "thread-id" value, it means that the didReceive(_:) method of your content extension will be multiple times. First when expanding the notification initially, and again whenever a new notification arrives with the same "thread-id" value.
I assume (hope) this will be added to the official documentation once iOS 10 is officially released.

Related

In swift remote notification is there a way to display a different message in the banner other than the one received from server when app is killed?

If my payload from the server is
{ "aps" : { "alert" : "You got a mail";
"badge" : 0;
}
"user": { "name" : "Nicole" } }`
And It also gives me some other data about the name of user who sent it . Is there a way to display custom message in the format : "Nicole sent a mail" in the notification center or banner ?
It is possible since iOS 10 by creating a Notification Service Extension. You can check the documentation for its details. Also, here is a good tutorial from Avanderlee that explains how to add Notification Service Extension to you app.

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

iOS push notification not received when screen is locked

I am using parse for push notification. Once I receive remote notification I pass it to the local notification, but issue is when screen is locked didReceiveRemoteNotification does not hit. I don't receive any notification.
I am using iOS8
Here's my payload:
{
CommentId = "8082a532-2380-4af5-bb3f-d247cfca519b";
CommentTitle = test; action = "com.lelafe.one4communities.Notifications.NotificationActivity";
aps = { };
moduleIdentifier = 8;
nTitle = "Comment posted by someone";
postingID = "c57a3d27-cfe5-41e9-a311-98a9fd7749ad";
}
There is one more parameter that you need to pass to your payload i.e. content-available and set its value to 1. It needs to be passed in case we wish that our app should receive notifications in the background.
The official documentation of parse describes this parameter as follows:
+content-available: (iOS only) If you are a writing a Newsstand app, or an app using the Remote Notification Background Mode introduced in iOS7 (a.k.a. "Background Push"), set this value to 1 to trigger a background download.
The problem is your dictionary aps:
Try checking out Apple's Documentation about The Notification Payload
Also Quoting #mamills answer:
If there is no badge, no alert, and no sound specified in the
dictionary (for the "aps" key) then a default message will not appear
and it will be completely silent.
Look again at example 5 in the document you referenced. aps can be
empty, and you can specify whatever custom data you would like as they
do with the "acme2" key. The "acme2" data is an example of where your
server's "special" payload could reside within the JSON payload.

send data with push notification - not returning whole push either

I have been trying for around 2 days now to get this chat app to work (really basic) that when the one user sends a message, it pops up as a remote notification on the other users screen and when they open it, it must take the second user to the specific chat (with the user that sent the message, not another chat from someone else).
I am trying to do this by unwrapping the notification, checking who the notification is from, and then taking them to the respective chat. But I cannot get the aps or the sent data to have the data from who it was.
I have done some research and other peoples notifications look like this:
{
"aps": {
"badge": 10,
"alert": "Test",
"sound": "cat.caf"
},
"url": "http://www.google.com"
}
While mine looks like this:
{
alert = asd;
}
1) is there a way to add more info such as sender id, sender name, etc.
2) how can I make this stop popping up as an alert, and rather just always have it as a banner?
Try this :
// Set your alert message
$message = 'How are you???!';
// Set your custom data
$customData = '{"url":"www.google.com"}';
// Create the payload body
$body['aps'] = array(
'alert' => $message,
'sound' => 'default',
'customData' => $customData
);
And finally push the payload.
Attaching the php file if you want : Push Custom Data
Parse appears to have documentation on this ... https://parse.com/docs/push_guide#top/iOS
Also pretty sure that the user has control over how the notifications should appear, you as a developer can't control it
So I managed to do it through the .setData() method. So here is the code:
var data: AnyObject = ["from" : "1", "message" : textView.text, "aps" : ["alert" : textView.text, "badge" : "1"]] as NSDictionary
push.setData(data as NSDictionary)
The reason it was not working earlier was because I was trying to use the .setMessage() as well, which overwrites the .setData() if it comes after, and vice versa.

iOS: Remote push notification showing key for button title instead of value

I'm implementing the usage of remote push notifications that uses a key to look up the Localizable.strings file, but the problem is that when I send a notification the alert dialog pops up with the key as the button title label instead of it's value.
So if I do the following for the main body of the push notification:
"body"=> "Test notification",
"action-loc-key"=>"ActionButtonInstall"
The app should look up the Localizable.strings file for the ActionButtonInstall key, which is "Install", but instead the alert dialog shows "ActionButtonInstall" as the button. I know that if the value for the key is null it will use a default OK button, but in this case it's not null, it just seems to fail to look it up, so I'm quite stuck with this.
Essentially, under what conditions would the notification button show up with the key instead of the value?
Thanks
Are your body and alert-loc-key keys in the body of an alert dictionary? It needs to be in the json format like so for the system to use it correctly:
"aps" : {
"alert" : {
"alert-loc-key" : "ActionButtonInstall",
"body" : "Test notification"
},
},

Resources