How to launch different screen of apple watch app from different notification?

浪子不回头ぞ 提交于 2019-12-12 19:01:22

问题


Problem:

How to launch different screen of apple watch app from different notification?

This is my setup:

I have 2 static WKUserNotificationInterfaceController:

1) awardsCategory

2) otherCategories

This is my PushNotificationPayload.apns file for "awardsCategory" notification:

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

}

Once I received a notification, pressing the notification sash or "Details" Button will launch the watch app:

How is it possible for the watch app to determined whether the notification is from awardsCategory or from otherCategories? And From there we can set our initial controller?


回答1:


When the user taps a button on the notification, the main interface controller is always displayed. handleActionWithIdentifier:forRemoteNotification: is called on your main controller and you can update the UI there. For example, you could hide certain elements, or push a different controller.

(If the user taps on the sash, the identifier will be an empty string.)



来源:https://stackoverflow.com/questions/28846155/how-to-launch-different-screen-of-apple-watch-app-from-different-notification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!