"WatchKit Simulator Actions"无法在实际的Apple Watch设备上运行

use*_*384 3 push-notification ios apple-watch

我测试了模拟苹果手表推送通知,它工作正常......

然而,当我试图将它发送到实际的苹果手表时,按钮没有出现......为什么会这样?

当我以json格式而不是文本发送推送通知时,它不会振动或发出哔哔声......

{
    "aps": {
        "alert": {
            "body": "Great!\nNew input",
            "title": "Optional title"
        },
        "category": "sCategory"
    },
    
    "WatchKit Simulator Actions": [
                                   {
                                   "title": "Details",
                                   "identifier": "sDetailsButtonAction"
                                   }
                                   ],
    
    "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)

在此输入图像描述

小智 7

看看这个.

要指定自定义操作按钮,您需要创建自定义通知类别.创建通知时,请将类别设置为自定义类别.

Apple文档中的示例:

func registerSettingsAndCategories() {
    var categories = NSMutableSet()

    var acceptAction = UIMutableUserNotificationAction()
    acceptAction.title = NSLocalizedString("Accept", comment: "Accept invitation")
    acceptAction.identifier = "accept"
    acceptAction.activationMode = UIUserNotificationActivationMode.Background
    acceptAction.authenticationRequired = false

    var declineAction = UIMutableUserNotificationAction()
    declineAction.title = NSLocalizedString("Decline", comment: "Decline invitation")
    declineAction.identifier = "decline"
    declineAction.activationMode = UIUserNotificationActivationMode.Background
    declineAction.authenticationRequired = false

    var inviteCategory = UIMutableUserNotificationCategory()

    inviteCategory.setActions([acceptAction, declineAction], forContext: UIUserNotificationActionContext.Default)
    inviteCategory.identifier = "invitation"
    categories.addObject(inviteCategory)

// Configure other actions and categories and add them to the set...

    var settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: categories)

    UIApplication.sharedApplication().registerUserNotificationSettings(settings)
}
Run Code Online (Sandbox Code Playgroud)