如何检查用户是否在 ios 9 或 ios 10 上启用了远程通知?
如果用户不允许或单击“否”,我想切换一条消息,询问他们是否要启用通知。
最佳答案
Apple 建议使用 UserNotifications
框架而不是共享实例。所以,不要忘记导入 UserNotifications
框架。由于此框架是 iOS 10 中的新框架,因此只有在为 iOS10+ 构建的应用程序中使用此代码才是安全的
let current = UNUserNotificationCenter.current()
current.getNotificationSettings(completionHandler: { (settings) in
if settings.authorizationStatus == .notDetermined {
// Notification permission has not been asked yet, go for it!
} else if settings.authorizationStatus == .denied {
// Notification permission was previously denied, go to settings & privacy to re-enable
} else if settings.authorizationStatus == .authorized {
// Notification permission was already granted
}
})
您可以查看官方文档以获取更多信息:https://developer.apple.com/documentation/usernotifications
关于ios - Swift ios 检查是否在 ios9 和 ios10 中启用了远程推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40531103/