在iOS9中,我们会提示用户是否喜欢通知并将其引导至设置页面,以便他们可以为我们的应用启用通知权限。但是,如下所示,没有选项可以在iOS 10中的应用程序权限设置中启用通知。是否有必须使用适当权限填充此列表的新进程?
代码
//check the notifications status. First the global settings of the device, then our stored settings
func checkGlobalNotifications() {
let grantedSettings = UIApplication.sharedApplication().currentUserNotificationSettings()
if grantedSettings!.types.rawValue & UIUserNotificationType.Alert.rawValue != 0 {
globalNotificationsEnabled = true
//if global notifications are on, then check our stored settings (user)
if CallIn.Settings.notificationsEnabled { notificationsOn() } else { notificationsOff() }
}
else {
globalNotificationsEnabled = false
//global notifications (iOS) not allowed by the user so disable them
notificationsOff()
}
}
答案 0 :(得分:8)
iOS 10推出了UNUserNotificationCenter,现在用于所有本地和推送通知。例如:
<button id="menu-toggle" class="menu-toggle"><?php _e( '<?php the_title(); ?>', 'twentysixteen' ); ?></button>
您可以使用 UNUserNotificationCenter.current().requestAuthorization(options: [.alert])
{ (granted, error) in
if granted == true{
NSLog("Granted")
UIApplication.shared.registerForRemoteNotifications()
}
if let error = error {
NSLog("Error: \(error.description)")
}
}
WWDC视频:https://developer.apple.com/videos/play/wwdc2016/707/