如何检查用户是否在 ios 9 或 ios 10 上启用了远程通知?
如果用户不允许或单击“否”,我想切换一条消息,询问他们是否要启用通知。
苹果推荐使用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 https://developer.apple.com/documentation/usernotifications
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)