2015-06-09 73 views
3

這適用於iOS 8及之前版本,因此它可能是iOS 9 beta中的一個錯誤 - 或者它是一種改變的行爲。註冊本地通知會返回UIUserNotificationTypeNone,用戶在iOS9上選擇「允許」後

請求允許用戶發送本地通知後 -

 NSSet *categories = ...; 
     UIUserNotificationType notificationTypes = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert; 
     UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:notificationTypes categories:categories]; 

     [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings]; 

和用戶選擇「允許」,application:didRegisterUserNotificationSettings:被稱爲與[notificationSettings types] == UIUserNotificationTypeNone

但是,下一次我運行registerUserNotificationSettings時,它將被調用正確的權限類型。

蘋果公司的參考資料沒有說明任何可能表明這是有意的,因此它可能是一個錯誤。

任何人都知道什麼是問題或如何解決它?

回答

-1

就發現,蘋果已經修改了他們的didRegisterUserNotificationSettings方法

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings 

- (void)application:(UIApplication * nonnull)application didRegisterUserNotificationSettings:(UIUserNotificationSettings * nonnull)notificationSettings 

不知道閹這將解決問題,但你可以試試。

+0

這並不是說,該方法被調用,所以它是正確的。另外我在Xcode上看不到'nonnull'... – Kof

1

可以解決這個問題(這有點兒看起來像一個bug)在application:didRegisterUserNotificationSettings:檢查[application currentUserNotificationSettings]代替