特别提示用户何时允许推送通知

时间:2017-01-15 22:06:46

标签: swift apple-push-notifications onesignal

嘿,我想在用户按下按钮后提示推送通知,而不是在应用启动后立即询问。我该怎么办?这就是我在我的app委托中所拥有的。

 OneSignal.initWithLaunchOptions(launchOptions, appId: "myKey")

 if application.responds(to: #selector(UIApplication.registerUserNotificationSettings(_:))) {
        let settings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)


        application.registerUserNotificationSettings(settings)
        application.registerForRemoteNotifications()

    } else {

        let types: UIRemoteNotificationType = [UIRemoteNotificationType.badge, UIRemoteNotificationType.alert, UIRemoteNotificationType.sound]
        application.registerForRemoteNotifications(matching: types)
    }

1 个答案:

答案 0 :(得分:0)

你不能使用链接到IBAction的UIButton吗?这样您就需要将应用程序更改为UIApplication.shared