这就是我们注册本地通知的方式
if UIApplication.instancesRespondToSelector(Selector("registerUserNotificationSettings:")) {
UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound], categories: nil));
}
我们如何为远程做同样的事情? 有没有办法让我们可以一次注册并为两者工作?
最佳答案
您可以编写一个包装函数来同时注册两者:
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()
}
关于ios - 注册本地和远程通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36792479/