How to delete all local notifications when an application is deleted from an iPhone

前端 未结 5 1963
既然无缘
既然无缘 2021-02-03 21:18

Let\'s say I set 5 local notification for an iPhone application, then the user deletes the app. If the app is installed again, it shows the previous notifications.

I kno

5条回答
  •  Happy的楠姐
    2021-02-03 21:32

    As others have mentioned, I think the best way to accomplish this is to have a flag in didFinishLaunchingWithOptions in the application delegate that checks if it is the first launch or not.

    If the app is being launched for the first time, you can call

    [[UIApplication sharedApplication] cancelAllLocalNotifications];
    

    This will cancel any existing notifications.

    For example:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    
        // this flag will need to be stored somewhere non-volatile such as using CoreData 
        // or user defaults
        if(flag == nil || [flag count] ==0){ 
    
           [[UIApplication sharedApplication] cancelAllLocalNotifications];
    
           // update your flag so that it fails this check on any subsequent launches
           flag = 1;
        }
    {
    

提交回复
热议问题