Cancelling a specific UILocalNotification

后端 未结 3 484
青春惊慌失措
青春惊慌失措 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 12:15

    I would suggest using the userInfo property on UILocalNotification, as others have mentioned. A simpler implementation that the accepted answer would be:

    for(UILocalNotification* notification in [[UIApplication sharedApplication]scheduledLocalNotifications])
    {
           if([[notification.userInfo objectForKey:@"notification_identifier"] isEqualToString:@"notification_001"])
           {
                [[UIApplication sharedApplication] cancelLocalNotification:notification];
           }
    }
    

    A for loop like this is much simpler. I'm not sure if it's more or less optimal, but it's certainly easier to read, and I assume you only have a few notifications to loop through anyway.

提交回复
热议问题