2015-11-22 21 views
4

我搞砸了UILocalNotification和通知操作 - 除了當我在我的類別中提供兩個Minimal操作時,所有按我期望的方式工作,當通過通知中心的滑動顯示操作時,最右側行動總是藍色的。UILocalNotification最小操作 - 一個藍色,一個清除?

由於在我的應用程序中的操作是平等的,我寧願他們都是清晰的灰色,而不是一個藍色,一個清晰。我知道我可以用destructive將它們都變成紅色,但這也是錯誤的,如果我明確地將destructive設置爲false,我仍然會得到一個藍色,一個清晰。

這裏的圖像顯示什麼,我說什麼:

enter image description here

這裏是我用來做它的代碼:

let note = UILocalNotification() 

note.fireDate = NSDate(timeIntervalSinceNow: 5) 
note.timeZone = NSTimeZone.defaultTimeZone() 

note.alertBody = "Actions: A and B" 
note.alertTitle = "Notification!" 

let action1 = UIMutableUserNotificationAction() 
action1.identifier = 「ACTION_A" 
action1.title = "A" 
action1.activationMode = .Background 

let action2 = UIMutableUserNotificationAction() 
action2.identifier = 「ACTION_B" 
action2.title = "B" 
action2.activationMode = .Background 

let category = UIMutableUserNotificationCategory() 
category.identifier = "ANSWERS_CATEGORY" 
category.setActions([action1, action2], forContext: .Default) 

note.category = 「ACTIONS_CATEGORY" 

let categories = Set(arrayLiteral: category) 
let settingsRequest = UIUserNotificationSettings(forTypes: [.Alert, .Sound, .Badge], categories: categories) 
UIApplication.sharedApplication().registerUserNotificationSettings(settingsRequest) 

UIApplication.sharedApplication().scheduleLocalNotification(note) 

回答

3

無論是HiGnotification programming guide不建議可以設置按鈕的背景顏色。我發現的最具體的參考文獻是後者,指出:

如果破壞性屬性爲NO,則該操作的按鈕顯示爲藍色;如果是YES,按鈕是紅色的。

這顯然是不準確的,因爲兩個非破壞性的行爲不都是藍色的,但它含蓄地表明,對於每一個顏色是自動的iOS設置

+0

讓我們希望我們比寓意多一點繼續 - 但感謝您挖掘它。 – Luke

+1

看起來這是正確的,我唯一的選擇是與它一起生活,或使它們都變成紅色;) – Luke