Sto scrivendo un metodo per verificare se le impostazioni utente correnti sono costituite da determinati tipi di notifica.Perché UIUserNotificationType.None restituisce true nelle impostazioni correnti quando viene concessa l'autorizzazione dell'utente?
Quando si controlla se le impostazioni correnti contengono UIUserNotificationsType.None, restituisce true per entrambi quando il permesso è stato dato e negato. Qualcuno saprebbe perché è così?
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
}
Quando l'autorizzazione è acceso:
Optional(<UIUserNotificationSettings: 0x7fabdb719360; types: (UIUserNotificationTypeAlert UIUserNotificationTypeBadge UIUserNotificationTypeSound);>) true true true true
quando il permesso è spento:
Optional(<UIUserNotificationSettings: 0x7f96d9f52140; types: (none);>) false false false true
mi sento come se fosse comportarsi normalmente (dato come è implementato), ma si sente come un bug a causa del fuorviante '.None'. Se '.None' è SEMPRE vero, allora perché lo abbiamo per cominciare? –