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

前端 未结 5 1899
既然无缘
既然无缘 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条回答
  •  离开以前
    2021-02-03 21:47

    You can use UIPasteboard to store a flag as DerekH already mentioned.
    Something link this:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
        if ([self mustCancelNotifications]) {
            [application cancelAllLocalNotifications];
            [self removeTag];
        } else {
            // Set your local notifications
            [self setFlag];
        }
    
        //...   
    
        // Override point for customization after application launch.
        return YES;
    }
    
    - (BOOL)mustCancelNotifications
    {
        UIPasteboard *past = [UIPasteboard generalPasteboard];
        NSString *s = [past valueForPasteboardType:@"my_app_local_notifications"];
        if (s) {
            return YES;
        }
        return NO;
    }
    
    - (void)setFlag
    {
        UIPasteboard *past = [UIPasteboard generalPasteboard];
        [past setValue:@"dummy" forPasteboardType:@"my_app_local_notifications"];
    }
    
    - (void)removeFlag
    {
        UIPasteboard *past = [UIPasteboard generalPasteboard];
        [past setData:nil forPasteboardType:@"my_app_local_notifications"];
    }
    

提交回复
热议问题