UIUserNotificationSettings不能工作
问题描述:
var categories: NSSet = NSSet(object: firstCategory)
let types: UIUserNotificationType = UIUserNotificationType.Badge | UIUserNotificationType.Alert
没有工作,并说二进制运算符'|'不能适用于两个“UIUserNotificationType”操作数UIUserNotificationSettings不能工作
var categories: NSSet = NSSet(object: firstCategory)
var mySettings = UIUserNotificationSettings = UIUserNotificationSettings(forTypes: [.Alert, .Badge], categories: categories)
也没有工作,并表示无法指定类型的不可变的表达“UIUserNotificationSettings.Type
答
这应该工作:
var categories = Set(arrayLiteral: firstCategory)
var mySettings = UIUserNotificationSettings(forTypes: [.Alert, .Badge], categories: categories)
你有太多=
在你的第二行。此外,您需要使用Set
而不是NSSet
。
答
尝试设置这样的:
var categories: Set = Set(object: firstCategory)
UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Alert, UIUserNotificationType.Badge categories: categories))
哇,非常感谢,我写错误':'为'='...... – postman99
有时Swift错误有误导性。 – Mark