2017-04-07 41 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) 
    { 
} 
相關問題