I read about your code, and found you have set UserDefaults to record the app whether requested, just like the Notification.
But in iOS 8, if users denied the Notification, system will remember the setting, then if the user uninstall the app and reinstall it, the requested record is definitely false, but the types of UIApplication.shared.currentUserNotificationSettings is definitely not equals to the UIUserNotificationType(),
so the logic will goes to the unknow,
I should call the first time Notification request here, right?
but I think the request alert will not appear, isn't it?
I did the testing like this:
if let types = UIApplication.shared.currentUserNotificationSettings?.types, types != UIUserNotificationType() {
Log.verbose("authorized");
}else{
if let bool = UserDefaults.standard.value(forKey: "test") as? Bool {
if bool {
Log.verbose("unauthorized");
}else{
let settings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil);
UIApplication.shared.registerUserNotificationSettings(settings);
Log.verbose("unknown");
}
}
}
just like what I said, the request alert is not appear after I reinstall the app if I denied before,
iOS 8.1 ~ 8.4 simulator are all not working.
so I think whether should to keep the requested record in KeyChain if iOS 8.1~8.4,
otherwise keep it in UserDefaults?
I read about your code, and found you have set
UserDefaults
to record the app whether requested, just like theNotification
. But in iOS 8, if users denied theNotification
, system will remember the setting, then if the user uninstall the app and reinstall it, therequested
record is definitelyfalse
, but thetypes
ofUIApplication.shared.currentUserNotificationSettings
is definitely not equals to theUIUserNotificationType()
, so the logic will goes to theunknow
, I should call the first timeNotification
request here, right? but I think the request alert will not appear, isn't it?I did the testing like this: if let types = UIApplication.shared.currentUserNotificationSettings?.types, types != UIUserNotificationType() { Log.verbose("authorized"); }else{ if let bool = UserDefaults.standard.value(forKey: "test") as? Bool { if bool { Log.verbose("unauthorized"); }else{ let settings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil); UIApplication.shared.registerUserNotificationSettings(settings); Log.verbose("unknown"); } } } just like what I said, the request alert is not appear after I reinstall the app if I denied before, iOS 8.1 ~ 8.4 simulator are all not working.
so I think whether should to keep the
requested
record inKeyChain
if iOS 8.1~8.4, otherwise keep it inUserDefaults
?