2016-06-13 106 views
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) 

回答

1

好吧,那麼我已經從蘋果開發者技術支持處得到了我的問題的答案。 張貼這在這裏,希望這將幫助別人:

首先要明白的是,「積極行動只是有線了對電話相關的通知(來電,未接來電和語音郵件)。目前沒有辦法通過應用警報的積極行動。

現在比較容易理解......