注册本地和远程通知
Posted
技术标签:
【中文标题】注册本地和远程通知【英文标题】:Register For Both Local And Remote Notification 【发布时间】:2016-04-22 11:20:34 【问题描述】:这就是我们注册本地通知的方式
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()
【讨论】:
以上是关于注册本地和远程通知的主要内容,如果未能解决你的问题,请参考以下文章