0

Dies ist, wie wir für die lokale BenachrichtigungRegister für lokale und Remote-Benachrichtigung

if UIApplication.instancesRespondToSelector(Selector("registerUserNotificationSettings:")) { 
    UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound], categories: nil)); 
} 

registrieren Wie können wir für Fernbedienung, um das gleiche zu tun? Gibt es einen Weg, wo wir uns einmal registrieren und für beide arbeiten können?

Antwort

1

Sie können eine Wrapper-Funktion schreiben für beide zur gleichen Zeit registrieren:

func initializeNotificationServices() { 
    let settings = UIUserNotificationSettings(forTypes: [.Sound, .Alert, .Badge], categories: nil) 
    UIApplication.sharedApplication().registerUserNotificationSettings(settings) //Local notifications 

    // This is an asynchronous method to retrieve a Device Token. You have to implement callbacks in AppDelegate to use the device token. 
    UIApplication.sharedApplication().registerForRemoteNotifications() 
}