2016-07-25 14 views
5

In iOS9 fordern wir unseren Benutzer auf, Benachrichtigungen zu erhalten und sie auf die Einstellungsseite zu leiten, damit sie die Benachrichtigungsberechtigung für unsere App aktivieren können. Wie unten gezeigt, gibt es keine Option, um Benachrichtigungen in meinen Apps-Berechtigungseinstellungen innerhalb von iOS 10 zu aktivieren. Gibt es einen neuen Prozess, den ich durchführen muss, um diese Liste mit den entsprechenden Berechtigungen zu füllen?Wie aktiviere ich Benachrichtigungen für iOS 10?

enter image description here

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

Antwort

8

iOS 10 hat UNUserNotificationCenter eingeführt, die für alle lokalen jetzt verwendet wird, und Push-Benachrichtigungen. Zum Beispiel:

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

Sie können die Einstellungen überprüfen mit getNotificationSettings()

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

+0

Ich möchte hinzufügen, dass die 'UIApplication.shared.registerForRemoteNotifications()' sollte nach 'gewährt erfolgen == wahr ' – KVISH

Verwandte Themen