Cancelling a specific UILocalNotification

后端 未结 3 497
青春惊慌失措
青春惊慌失措 2021-02-01 11:18

I have this code for local notification, and I have a scheduleNotification and clearNotification using my own method. These are the codes:

- (void)clearNotificat         


        
3条回答
  •  悲哀的现实
    2021-02-01 11:55

    NSArray *notifications = [[UIApplication sharedApplication] scheduledLocalNotifications];
    for (UILocalNotification *not in notifications) {
        NSString *dateString=[not.userInfo valueForKey:@"EndDate"];
        if([dateString isEqualToString:@"CompareString"])
        { 
            [[UIApplication sharedApplication] cancelLocalNotification:not];
        }
    }
    
    1. Give user info whenever you create local notification (this is a key-value pair).
    2. Iterate through notifications (it contains All Local Notifications) and compare value for the known key. In the above example I am using EndDate as the key and CompareString as the value.

    Its Working Fine With Me.

    Cheers..

提交回复
热议问题