2015-08-27 22 views
6

Geçerli kullanıcı ayarlarının belirli bildirim türlerinden oluştuğunu kontrol etmek için bir yöntem yazıyorum.Kullanıcı izni verildiğinde, neden UIUserNotificationType.None geçerli ayarlarda doğrudur?

Geçerli ayarların UIUserNotificationsType.None içerip içermediğini denetlerken, hem izin verildiğinde hem de reddedildiğinde, doğru olarak döner. Bunun neden olduğunu bilen var mı?

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 
} 

izni üzerindedir: izni kapalı olduğunda

Optional(<UIUserNotificationSettings: 0x7fabdb719360; types: (UIUserNotificationTypeAlert UIUserNotificationTypeBadge UIUserNotificationTypeSound);>) true true true true

:

Optional(<UIUserNotificationSettings: 0x7f96d9f52140; types: (none);>) false false false true

+0

Ben normalde davranıyor gibi (nasıl uygulandığı verilen) fakat yanıltıcı '.None' bir böcek gibi hissediyor hissediyorum. Eğer '.None' HER ZAMAN doğruysa, neden başlıyoruz? –

cevap

2

tuhaf yönü sadece 0 0 :) bir atın içerdiğini teyit UIUserNotificationsType için enum definition baktype: https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIUserNotificationSettings_class/index.html#//apple_ref/c/tdef/UIUserNotificationType

struct UIUserNotificationType : OptionSetType { 
    init(rawValue rawValue: UInt) 
    static var None: UIUserNotificationType { get } 
    static var Badge: UIUserNotificationType { get } 
    static var Sound: UIUserNotificationType { get } 
    static var Alert: UIUserNotificationType { get } 
} 

Ama Objective-C daha bile görülebilir:

typedef enum UIUserNotificationType : NSUInteger { 
    UIUserNotificationTypeNone = 0, 
    UIUserNotificationTypeBadge = 1 << 0, 
    UIUserNotificationTypeSound = 1 << 1, 
    UIUserNotificationTypeAlert = 1 << 2, 
} UIUserNotificationType; 
+0

Bunu anlıyorum. Yine de kafamda, api içeriklerini tek başına kullanmanın kullanıcının izin vermediğini kontrol etmek için yeterli olacağını umuyorum. Bu bilinen/kabul edilen bir davranış olup olmadığını merak ediyorum – micap

İlgili konular