gpt4 book ai didi

ios - 注册本地和远程通知

转载 作者:行者123 更新时间:2023-11-29 01:02:58 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com