user1872384
user1872384

Reputation: 7127

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

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

enter image description here

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:

enter image description here

enter image description here

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?

Upvotes: 2

Views: 1813

Answers (1)

Aaron Brager
Aaron Brager

Reputation: 66244

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

Upvotes: 3

Related Questions