How to clear push notification badge count in iOS?

前端 未结 5 2332
挽巷
挽巷 2020-12-14 00:09

I want to clear the push notification badge count once app is launched.Im not clear where to set the below code.Please give brief description about clearing the badge count.

5条回答
  •  抹茶落季
    2020-12-14 00:39

    You should set this:

    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;

    in either of these AppDelegate methods if the application is launched and sent to background then you launch the application didFinishLaunchingWithOptions method will not be called so use either of these methods:

    - (void)applicationWillEnterForeground:(UIApplication *)application
    
    - (void)applicationDidBecomeActive:(UIApplication *)application
    

    For Swift 3+

    - func applicationWillEnterForeground(_ application: UIApplication)
    - func applicationDidBecomeActive(_ application: UIApplication)
    

提交回复
热议问题