第一次启动时如何防止通知权限?

How to prevent notification permission when I launch first time?

我有一个特殊按钮请求允许通知的权限,但我在单击该按钮之前看到了权限。有人知道如何禁用它吗?

谢谢!

我一直在 AppDelegate.swift

        alarmScheduler.setupNotificationSettings()
    window?.tintColor = UIColor.red

    let notificationSettings = UIUserNotificationSettings(types: .alert, categories: nil)
    UIApplication.shared.registerUserNotificationSettings(notificationSettings)

所以我就把它删除了,解决了我的麻烦

试试这个想法,未测试 控制器

在你的viewcontroller

中调用UIApplicationDelegate

按钮操作中

registerForRemoteNotification()

func registerForRemoteNotification() {
    if #available(iOS 10.0, *) {
        let center  = UNUserNotificationCenter.current()
        center.delegate = self
        center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in
            if error == nil{
                UIApplication.shared.registerForRemoteNotifications()
            }
        }
    }
    else {
        UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.sound, .alert, .badge], categories: nil))
        UIApplication.shared.registerForRemoteNotifications()
    }
}

并实施跟随代表,

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)
    {
}