2
我试图与苹果通知中心服务一起使蓝牙外设和iOS设备进行交互。 在documentation苹果提2个通知操作:EventFlagPositiveAction和EventFlagNegativeAction ...ANCS:PositiveAction的概念是什么?
到目前为止,负部分的工作原理:一旦通知被发送到外围,后者可以引发的负面作用,导致解雇通知。
但我不能触发力的正侧...我的通知有一个单一的动作按钮,我想这个按钮被视为积极的行动......但我不知道它是如何工作:它是隐含的吗?做所有动作正面标志?或者我应该做些什么来使它被识别为正面一个?
这更多的是关于ACNS一个概念性的问题,但对于信息,下面是我使用的代码:
1日至在AppDelegate的当地注册通知:
let notificationTypes = UIUserNotificationType.Alert.union(UIUserNotificationType.Sound).union(UIUserNotificationType.Badge)
let launchAction = UIMutableUserNotificationAction()
launchAction.identifier = "LAUNCH_ACTION"
launchAction.title = "OK"
launchAction.activationMode = UIUserNotificationActivationMode.Foreground
launchAction.destructive = false
/* this is this UIMutableUserNotificationAction that I want to trigger from my external device, and should be considered as the famous positive action I am looking for */
let notificationCategory = UIMutableUserNotificationCategory()
notificationCategory.identifier = "LAUNCH_NOTIFICATION"
notificationCategory.setActions([launchAction], forContext: .Minimal)
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: notificationTypes, categories: NSSet(array:[notificationCategory]) as? Set<UIUserNotificationCategory>))
和2 ,稍后创建通知
let localNotification:UILocalNotification = UILocalNotification()
localNotification.alertAction = "Hello"
localNotification.alertBody = "World"
localNotification.fireDate = NSDate(timeIntervalSinceNow: 5)
localNotification.soundName = UILocalNotificationDefaultSoundName
localNotification.hasAction = true
localNotification.category = "LAUNCH_NOTIFICATION"
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)