What is the correct way to trigger a notification permissions dialog from a button press?
All of the tutorials place the permission dialog trigger in appDelegate so as soon as the application is loaded a permissions dialog appears.
答案 0 :(得分:3)
我想你刚回答了自己的问题。将要求通知权限的代码移动到按下按钮调用的函数。它可能看起来像这样:
@IBAction func buttonPressed() {
registerUserNotificationSettings()
}
func registerUserNotificationSettings() {
let userNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound
let settings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
}