Vasily
Vasily

Reputation: 3790

Request permission to receive push on action

I want ask user's permission only after user pushes button in ViewController. How can I do that?

In my code dialog popups after application launch. I can't execute application.registerUserNotificationSettings anywhere except AppDelegate class (i'm always getting errors).

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
}

Upvotes: 0

Views: 623

Answers (1)

Deny
Deny

Reputation: 1461

You can use this where you want:

UIApplication.sharedApplication().registerUserNotificationSettings(settings)

Upvotes: 1

Related Questions