How to clear the remote notification in your app?

前端 未结 8 1938
青春惊慌失措
青春惊慌失措 2021-02-04 03:01

Is there a way to clear the remote notification from the notification banner when swiping down from the top of the iPhone screen. I tried setting the badge number to zero:

8条回答
  •  轮回少年
    2021-02-04 03:22

    In Nov, 2019 below is the working solution for me with Swift 4. First you have to check the device version to clear all notifications but do not need to check to reset badge count.

    override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?  ) -> Bool {
    
      //--------
    
      application.applicationIconBadgeNumber = 0
      if #available(iOS 10.0, *) {        
         let center = UNUserNotificationCenter.current() 
         center.removeAllDeliveredNotifications() 
         center.removeAllPendingNotificationRequests()    
      } else {        
         application.cancelAllLocalNotifications()    
      }        
    
      //------
    }
    

提交回复
热议问题