我有一个特殊的按钮,请求允许通知的权限但我在点击按钮之前看到了权限。有人知道如何禁用它吗?
谢谢!
答案 0 :(得分:0)
我一直在AppDelegate.swift中使用
alarmScheduler.setupNotificationSettings()
window?.tintColor = UIColor.red
let notificationSettings = UIUserNotificationSettings(types: .alert, categories: nil)
UIApplication.shared.registerUserNotificationSettings(notificationSettings)
所以我刚删除它并解决了我的麻烦
答案 1 :(得分:0)
尝试这个想法,未经测试与控制器
在 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)
{
}