【发布时间】: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