【发布时间】:2015-08-27 19:51:07
【问题描述】:
我正在编写一种方法来检查当前用户设置是否包含某些通知类型。
在检查当前设置是否包含 UIUserNotificationsType.None 时,在授予权限和拒绝权限时都返回 true。有谁知道这是为什么?
func registerForAllNotificationTypes()
{
registerNotificationsForTypes([.Badge, .Alert, .Sound])
}
func registerNotificationsForTypes(types:UIUserNotificationType)
{
let settings = UIUserNotificationSettings.init(forTypes:types, categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
}
func isRegisteredForAnyNotifications() -> Bool
{
let currentSettings = UIApplication.sharedApplication().currentUserNotificationSettings()
print(currentSettings)
print((currentSettings?.types.contains(.Alert))!)
print((currentSettings?.types.contains(.Badge))!)
print((currentSettings?.types.contains(.Sound))!)
print((currentSettings?.types.contains(.None))!)
return (currentSettings?.types.contains(.Alert))! //Just testing .Alert for now
}
权限开启时:
Optional(<UIUserNotificationSettings: 0x7fabdb719360; types: (UIUserNotificationTypeAlert UIUserNotificationTypeBadge UIUserNotificationTypeSound);>)
true
true
true
true
权限关闭时:
Optional(<UIUserNotificationSettings: 0x7f96d9f52140; types: (none);>)
false
false
false
true
【问题讨论】:
-
我觉得它的行为正常(考虑到它的实现方式),但感觉就像一个错误,因为
.None具有误导性。如果.None总是正确的,那我们为什么要从它开始呢?