2017-04-07 64 views
0

我有一个特殊的按钮,请求允许通知的权限,但我在点击按钮之前看到权限。有人知道如何禁用它吗?第一次启动时如何防止通知许可?

谢谢!

+0

你implment –

+0

按钮的touchUpInside执行代码,而不是didFinishLaunching分享代码解决方案 –

回答

0

我一直在使用中AppDelegate.swift

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

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

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

0

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

呼叫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) 
    { 
} 
相关问题