Watch App通知的有效负载

edw*_*dmp 7 apple-push-notifications ios watchkit

在Xcode中创建新的Apple Watch应用程序时,会创建以下APNS有效负载示例:

{
    "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." }
Run Code Online (Sandbox Code Playgroud)

我对在警报字典中使用正文和标题感到困惑.以下有效内容通常用于iOS应用程序:

{
    "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."
}
Run Code Online (Sandbox Code Playgroud)

哪种方法正确?尽管以这种方式创建了默认有效负载文件,但Apple文档使用后一种变体提供了屏幕截图.

小智 1

《本地和远程通知编程指南》(表3-1)中, key 的值类型alert可以是string 或dictionary,正如 Dhawal 所说,两种格式都是正确的。

如果alert是字典,则可以包含titlebodytitle-loc-key(表3-2)。钥匙的用途是什么title?这个键是在包含WatchKit的iOS 8.2中添加的,而WatchKit有一个Short-Look Notification接口,没有足够的空间来容纳完整的通知,所以Apple Watch使用titleShort-Look Notification来描述通知的目的并显示。


(来源:edgekey.net

在这张照片中,“格雷的生日”titlealert。因为您在模拟器中看不到短视通知,所以您应该title在真实的 Apple Watch 中测试按键结果。