Application Payload Notification Payload

When you create a new Apple Watch application in Xcode, the following APNS payload example is created:

{ "aps": { "alert": { "body": "Test message", "title": "Optional title" }, "category": "myCategory" }, "WatchKit Simulator Actions": [ { "title": "First Button", "identifier": "firstButtonAction" } ], "customKey": "Use this file to define a testing payload for your notifications. The aps dictionary specifies the category, alert text and title. The WatchKit Simulator Actions array can provide info for one or more action buttons in addition to the standard Dismiss button. Any other top level keys are custom payload. If you have multiple such JSON files in your project, you'll be able to select them when choosing to debug the notification interface of your Watch App." } 

I am confused by the use of the body and name in the alert dictionary. IOS applications typically use the following payload:

 { "aps": { "alert": "Test message", "title": "Opt title", "category": "default" }, "WatchKit Simulator Actions": [ { "title": "First Button", "identifier": "firstButtonAction" } ], "customKey": "Use this file to define a testing payload for your notifications. The aps dictionary specifies the category, alert text and title. The WatchKit Simulator Actions array can provide info for one or more action buttons in addition to the standard Dismiss button. Any other top level keys are custom payload. If you have multiple such JSON files in your project, you'll be able to select them when choosing to debug the notification interface of your Watch App." } 

What is the right way? Although the default payload file is created this way, Apple's documentation provides a screenshot using the latter.

+7
ios watchkit apple-push-notifications
source share
3 answers

In the Local and Remote Notification Programming Guide (Table 3-1), the alert key value type can be a string or a dictionary , as Dhawal said, both formats are correct.

If alert is a dictionary, it may contain title , body , title-loc-key , etc. (Table 3-2). What is the purpose of the title key? This key was added in iOS 8.2, which contains WatchKit, and WatchKit has a Short-Look notification interface, there is not enough space for a full notification, so Apple Watch uses the title to describe the purpose of the notification and display in the Short-Look Notification.


(source: edgekey.net )

In this picture, "Gray Birthday" is the title in the alert . Since you do not see a short glance notification in the simulator, you should check the result of pressing the title key in REAL Apple Watch.

+1
source share

Based on Apple's documentation , the following keys are provided that you can use in the aps dictionary: alert , badge , sound and content-available . And here are the keys you can find in the alert dictionary: name, body, name-loc-args, etc. You can check out this Push Notification Programming Guide for more information here: Push Notification Programming Guide

Check it out also for WatchKit Extension , Apple Watch Programming Guide

In addition, the second method that you describe should be correct. I just create a Watch App and includes an approximate payload. And category is placed inside aps outside alert , which should be wrong in this case. Hope this helps. This means that aps can only contain those four properties by default. So, category should be contained inside alert .

0
source share

Apple Documentation for Push Notification Payload mentions a note,

Note. If you want the device to display the message text as is in the warning, which has the Close and Open buttons, then specify the line as a direct warning value. Do not specify a dictionary as a warning value if the dictionary has only the body property.

So, as stated above, both formats are correct, but we must use the second format (warning with a direct text value instead of a dictionary) when you only need the body property in Alert. If you need to use other child properties of Alert, such as body, title, ..., then you should use the first format (Alert with a dictionary as a value).

0
source share

All Articles