2016-10-31 111 views
0
var category:UIMutableUserNotificationCategory=UIMutableUserNotificationCategory() 
category.identifier="DEFAULT_GATEGORY" 
let defaultAction:NSArray=[action] 
category.setActions(defaultAction as [AnyObject] as [AnyObject], forContext: UIUserNotificationActionContext.Minimal) 
+0

是什麼類型'action'? –

+0

@JefferyThomas UIMutableUserNotificationAction – nene

+0

如果你解釋你的情況,你到底做了什麼,你做了什麼等,它會很好。它可以幫助其他用戶幫助你:D –

回答

0

假設actionUIUserNotificationAction類型:

var category = UIMutableUserNotificationCategory() // NOTE: type not needed. 
category.identifier = "DEFAULT_GATEGORY" 
let defaultAction = [action] // NOTE: Type not needed. 
category.setActions(defaultAction, forContext: UIUserNotificationActionContext.Minimal) 

正如你看到的,我所做的就是刪除不需要的(和誤導)類型的信息。我發現依靠Swift的自動類型確定系統是有幫助的。


測試了以下游樂場代碼:

let action = UIMutableUserNotificationAction() 
var category = UIMutableUserNotificationCategory() 
category.identifier = "DEFAULT_GATEGORY" 
let defaultAction = [action] 
category.setActions(defaultAction, forContext: UIUserNotificationActionContext.Minimal) 
相關問題