0

這就是我們如何註冊本地通知註冊爲本地和遠程通知

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

我們如何做同樣的遠程? 我們可以註冊一次併爲兩者工作嗎?

回答

1

您可以編寫一個包裝函數在同一時間兩個註冊:

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