ios - "WatchKit Simulator Actions"不适用于实际的 Apple Watch 设备

标签 ios push-notification apple-watch

我已经测试了模拟的 apple watch 推送通知,它工作正常......

但是当我尝试将它发送到实际的 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."
}

enter image description here

最佳答案

看看this .

要指定自定义操作按钮,您需要创建一个自定义通知类别。创建通知时,将类别设置为您的自定义类别。

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

关于ios - "WatchKit Simulator Actions"不适用于实际的 Apple Watch 设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30255063/

相关文章:

ios - 在 tableviewCell 类中找不到属性 “bounds”

java - WebSockets - 创建 channel 和推送数据的正确方法

ios - 推送通知在 UIApplication LaunchOptions RemoteNotificationKey 中不起作用

ios - 如何在 Apple Watch 项目上获取页面点

ios - 如何使用 NSFetchedResultsController 建立 A-Z 索引

iphone - 验证文本字段 : highlighted red border, iPhone

watchkit - 在 WatchKit 中重新加载表

ios - 从 iOS 打开 WatchKit 应用程序

objective-c - 如何在没有一长串 if 语句的情况下将 float 映射到枚举

ios - iOS推送通知,收到消息后自动响应服务器