我想在用户按下ViewController中的按钮后才询问用户的权限。我怎么能这样做?
在应用程序启动后的代码对话框弹出窗口中。我无法在除AppDelegate类之外的任何地方执行 application.registerUserNotificationSettings (我总是遇到错误)。
AppDelegate.swift:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Notifications
let notificationType = UIUserNotificationType.Alert
let settings = UIUserNotificationSettings(forTypes: notificationType, categories: nil)
application.registerUserNotificationSettings(settings) // <-- that method popups dialog to allow/decline Push
// Override point for customization after application launch.
return true
}
答案 0 :(得分:1)
您可以在任意位置使用:
UIApplication.sharedApplication().registerUserNotificationSettings(settings)