Include APS payload data in local notification to watchOS

350 views Asked by At

I'm trying to display a custom Long-Look UI when receiving a local notification on my watch extension.

I tested this sample .apns payload:

{
    "aps": {
        "alert": {
            "body": "Test message",
            "title": "Optional title"
        },
        "category": "myCategory",
        "thread-id":"5280"
    },

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

and it works fine. I also have a dynamic notification scene designed on the storyboard.

I'm scheduling local notifications from the iOS side like this (and lock the phone right afterward to force the notification to go on my watch)

let content = UNMutableNotificationContent()
content.title = "Early bird"
content.categoryIdentifier = "myCategory"
content.userInfo = [
            "userData": [
                "WatchKit Simulator Actions": [
                    [
                        "title": "Button 1",
                        "identifier": "button1Action",
                    ],
                    [
                        "title": "Button 2",
                        "identifier": "button2Action",
                    ]
                ]
            ]
        ]

I think I'm setting my userInfo wrong. How do I set the correct payload so my watchOS extension can render the long-look correctly?

0

There are 0 answers