Ios 如何防止两次注册通知设置?

Ios 如何防止两次注册通知设置?,ios,swift,swift2,uilocalnotification,Ios,Swift,Swift2,Uilocalnotification,我正在我的AppDelegate中注册通知设置。didFinishLaunchingWithOptions事件如下: let notificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound let acceptAction = UIMutableUserNotificationAction() acceptAction.identifier

我正在我的
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将只显示一次提示。您可以根据需要多次调用它。