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