if UIApplication.sharedApplication().isRegisteredForRemoteNotifications() == true {
println("Yes, allowed")
println(UIApplication.sharedApplication().isRegisteredForRemoteNotifications())
} else {
//ignore
return
}
当我转到设置以完全关闭通知然后返回应用程序时,该应用程序仍然打印 true, allowed。
我似乎无法让它触发 false,即使在应用程序卸载/重新安装之后也是如此。
最佳答案
我为 Swift 3 做了一个扩展
extension UIApplication {
func remoteNotificationsEnabled() -> Bool {
var notificationsEnabled = false
if let userNotificationSettings = currentUserNotificationSettings {
notificationsEnabled = userNotificationSettings.types.contains(.alert)
}
return notificationsEnabled
}
}
比起使用它
UIApplication.shared.remoteNotificationsEnabled()
关于ios - isRegisteredForRemoteNotifications 返回 true 即使我完全禁用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29787736/