ios - 注册本地和远程通知

标签 ios swift push-notification apple-push-notifications uilocalnotification

这就是我们注册本地通知的方式

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/

相关文章:

iOS 7/8 半透明导航栏右上角黑色

ios - 如何根据内容动态设置 tableview 的高度,但它应该与底部按钮保持最小距离?

ios - FacebookSDK 无法登录,授权后出现空白屏幕。

Swift - CollectionView,如何查找 IndexPath 中的第一个和最后一个项目?

ios - 发送通用推送通知 - Xcode

python - 接收 onesignal.com 通知

ios - 如何在 UIPickerView 中添加部分标题?

ios - Swift UITableView 多行单元格

ios - 如何在调用 SOAP 网络服务时显示事件指示器?

android - 如何通过点击推送消息通知来判断应用程序已启动