申请通知权限注册后(不仅仅是应用程序启动后)

时间:2016-08-05 12:33:15

标签: ios push-notification swift2

我们可以更改Permission seek方法的默认行为(它在我们启动应用程序时出现)但是我希望在用户注册时显示它,我在appDelegate中执行此操作:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    let notificationSettings = UIUserNotificationSettings(
        forTypes: [.Badge, .Sound, .Alert], categories: nil)


    application.registerUserNotificationSettings(notificationSettings)

    return true
}

1 个答案:

答案 0 :(得分:4)

您可以将它放在您想要询问用户的不同类别中,如下所示

let notificationSettings = UIUserNotificationSettings(
            forTypes: [.Badge, .Sound, .Alert], categories: nil)

UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings)