【问题标题】:Apple watch notification mirroring苹果手表通知镜像
【发布时间】:2016-02-06 13:25:36
【问题描述】:

我正在尝试在 Apple Watch 上创建带有操作的通知。然而,文档并没有真正说明什么是原生的,应该做什么。

目前我正在 iPhone 上创建 UILocalNotification。但是我想知道的是,操作按钮会镜像到 Apple Watch 上。

我用来在 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)

我是否应该做任何事情来确保按钮可以在 Apple Watch 上使用?还是我只需要为通知创建一个 watchkit 应用?

【问题讨论】:

    标签: ios iphone swift apple-watch


    【解决方案1】:

    您可以免费获得默认通知,但用户唯一的选择是关闭它。

    如果你想要一些自定义的东西,那么你想创建自己的监视目标并在监视目标故事板中构建不同的通知视图

    这是 Apple Watch Programming Kit 上的 page,它解释了您可以制作的不同自定义通知

    【讨论】:

    • 感谢您的澄清!
    • 如果您需要任何其他示例,请告诉我
    • 好吧,我已经搜索了一些,但我刚刚找到的是:stackoverflow.com/questions/28265134/… 其中说后台操作将在 Apple Watch 上可见。因此,如果我只想要带有操作的通知,我不需要整个 watchkit 应用程序?
    • @marc 这是苹果解释不同的页面developer.apple.com/library/ios/documentation/General/…
    • 这样就搞定了。显然,我已经通过将其添加到正常通知中来添加监视操作支持。再次感谢!
    猜你喜欢
    • 2022-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-07
    • 2011-09-19
    • 2011-05-19
    相关资源
    最近更新 更多