简体   繁体   English

Apple Watch通知镜像

[英]Apple watch notification mirroring

I'm trying to create a notification with an action on the Apple Watch. 我正在尝试在Apple Watch上创建带有操作的通知。 However the documentation is not really saying what is native and what should be made. 但是,文档并没有真正说明什么是本地的,应该做什么。

Currently I'm creating a UILocalNotification on the iPhone. 目前,我正在iPhone上创建UILocalNotification。 However what I'm wondering is that the action button will be mirrored on the Apple Watch. 但是,我想知道的是,操作按钮会镜像到Apple Watch上。

The code I'm using to create the notification on the iPhone is: 我用来在iPhone上创建通知的代码是:

    let incrementAction = UIMutableUserNotificationAction()
    incrementAction.identifier = "OPEN_ACTION"
    incrementAction.title = "Open"
    incrementAction.activationMode = UIUserNotificationActivationMode.Background
    incrementAction.authenticationRequired = false
    incrementAction.destructive = false

    let counterCategory = UIMutableUserNotificationCategory()
    counterCategory.identifier = "SLAGBOOM_CATEGORY"

    counterCategory.setActions([incrementAction],
    forContext: UIUserNotificationActionContext.Default)

    counterCategory.setActions([incrementAction],
    forContext: UIUserNotificationActionContext.Minimal)

    let types = UIUserNotificationType.Alert
    let settings = UIUserNotificationSettings(forTypes: types, categories: NSSet(object: counterCategory) as? Set<UIUserNotificationCategory>)
    UIApplication.sharedApplication().registerUserNotificationSettings(settings)

    let notification:UILocalNotification = UILocalNotification()
    notification.alertBody = message
    notification.category = "SLAGBOOM_CATEGORY"
    UIApplication.sharedApplication().scheduleLocalNotification(notification)

Am I supposed to do anything to make sure the button will work on the Apple Watch? 我是否应该做任何事情来确保该按钮在Apple Watch上可以使用? Or do I need to create a watchkit app only for a notification? 还是仅需要为通知创建Watchkit应用?

You get default notifications for free but the users only option is to dismiss it. 您可以免费获得默认通知,但用户唯一的选择是将其关闭。

If you want something custom then you want to create your own watch target and build out the different notification views in the watch targets storyboard 如果您想自定义某项内容,则需要创建自己的监视目标并在监视目标情节提要中构建不同的通知视图

Here's the page on Apple's Watch Programming Kit the explains the different custom notifications you can make 这是Apple Watch编程套件上的页面 ,解释了您可以发出的各种自定义通知

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM