如何从不同的通知启动不同的苹果手表应用程序屏幕?

时间:2015-03-04 03:23:19

标签: push-notification watchkit apple-watch

问题:

如何从不同的通知中启动不同的苹果手表应用程序屏幕?

这是我的设置:

我有2个静态WKUserNotificationInterfaceController:

1)awardsCategory

2)otherCategories

enter image description here

这是我的PushNotificationPayload.apns文件,用于" awardsCategory"通知:

{
"aps": {
    "alert": {
        "body": "Hello world!",
        "title": "Optional title"
    },
    "category": "salaryCategory"
},

"WatchKit Simulator Actions": [
                               {
                               "title": "Details",
                               "identifier": "detailsButtonAction"
                               }
                               ],

"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."

}

收到通知后,按通知窗框或"详细信息"按钮将启动手表应用程序:

enter image description here

enter image description here

手表应用程序如何确定通知是来自awardsCategory还是来自其他类别?从那里我们可以设置我们的初始控制器?

1 个答案:

答案 0 :(得分:3)

当用户点击通知上的按钮时,将始终显示主界面控制器。在您的主控制器上调用handleActionWithIdentifier:forRemoteNotification:,您可以在那里更新UI。例如,您可以隐藏某些元素,或推送不同的控制器。

(如果用户点击窗框,标识符将为空字符串。)