我正在尝试使用 Apple 通知中心服务在蓝牙外围设备和 iOS 设备之间进行交互。
在 documentation Apple 提到了 2 个通知 Action :EventFlagPositiveAction 和 EventFlagNegativeAction……
到目前为止,Negative 部分起作用:一旦通知被传输到外围设备,后一个可以触发否定操作,从而导致通知被解除。
但我无法触发力量的积极方面...我的通知有一个操作按钮,我希望此按钮被视为积极行动...但我不知道它是如何工作的:它是隐式的吗?所有 Action 都有 positive 标志吗?还是我应该做点什么让它被认为是积极的?
这更多是关于 ACNS 的概念性问题,但为了提供信息,下面是我正在使用的代码:
第一次在 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>))
第二,稍后创建通知
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)
Best Answer-推荐答案 strong>
好的,那么我已经从 Apple 开发人员技术支持那里得到了我的问题的答案。
在这里发布,希望这对其他人有帮助:
the first thing to understand is that “Positive actions are only wired up for telephony related notifications (incoming call, missed call, and voicemail). There is currently no way to pass through the positive action for an app alert.
现在事情更容易理解了……
关于ios - ANCS : what is the concept of PositiveAction?,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/37795587/
|