gpt4 book ai didi

ios - 如何防止通知设置被重复注册?

转载 作者:行者123 更新时间:2023-11-30 13:38:33 25 4
gpt4 key购买 nike

我正在我的 AppDelegate.didFinishLaunchingWithOptions 事件中注册通知设置,如下所示:

let notificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound
let acceptAction = UIMutableUserNotificationAction()
acceptAction.identifier = "Accept"
acceptAction.title = "Accept"
acceptAction.activationMode = UIUserNotificationActivationMode.Background
acceptAction.destructive = false
acceptAction.authenticationRequired = false

let declineAction = UIMutableUserNotificationAction()
declineAction.identifier = "Decline"
declineAction.title = "Decline"
declineAction.activationMode = UIUserNotificationActivationMode.Background
declineAction.destructive = false
declineAction.authenticationRequired = false

let category = UIMutableUserNotificationCategory()
category.identifier = "invite"
category.setActions([acceptAction, declineAction], forContext: UIUserNotificationActionContext.Default)
let categories = NSSet(array: [category])
let settings = UIUserNotificationSettings(forTypes: notificationType, categories: categories)
application.registerUserNotificationSettings(settings)

如何防止我的应用程序注册两次,以防用户退出应用程序并稍后返回,或者多次重新注册是否无害?

最佳答案

用户被提示一次通知后,就不会再被询问。您可以在模拟器中亲自验证这一点。因此,那里的代码原样就很好。

关于ios - 如何防止通知设置被重复注册?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35831103/

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