繁体   English   中英

如何为iOS 10启用通知?

[英]How do I enable notifications for iOS 10?

在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()
    }
}

iOS 10引入了UNUserNotificationCenter,现在用于所有本地和推送通知。 例如:

    UNUserNotificationCenter.current().requestAuthorization(options: [.alert])
    { (granted, error) in
        if granted == true{
            NSLog("Granted")
             UIApplication.shared.registerForRemoteNotifications()
        }
        if let error = error {
            NSLog("Error: \(error.description)")
        }
    }

您可以使用getNotificationSettings()检查设置

WWDC视频: https//developer.apple.com/videos/play/wwdc2016/707/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM