简体   繁体   中英

How do I enable notifications for iOS 10?

In iOS9 we prompt our user if they'd like notifications and direct them to the settings page so they can enable notification permission for our app. However as shown below there is no option to enable notifications in my apps permissions settings within iOS 10. Is there a new process I must undertake to populate this list with the appropriate permissions?

在此输入图像描述

Code

//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 has introduced UNUserNotificationCenter, which is used now for all local and push notifications. For example:

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

You can check the settings using getNotificationSettings()

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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