Cancelling a specific UILocalNotification

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

    (void)cancelLocalNotification:(NSString*)notificationID
    {
    
       // UILocalNotification *cancelThisNotification = nil;
      //  BOOL hasNotification = NO;
    
        for (int j =0;j<[[[UIApplication sharedApplication]scheduledLocalNotifications]count]; j++)
        {
            UILocalNotification *someNotification = [[[UIApplication sharedApplication]scheduledLocalNotifications]objectAtIndex:j];
            if([[someNotification.userInfo objectForKey:@"drdid"] isEqualToString:notificationID])
            {
                NSLog(@"id,notificationID(App) %@ %@ ",[someNotification.userInfo objectForKey:@"drdid"],notificationID);
                NSLog(@"canceled notifications %@",someNotification);
               [[UIApplication sharedApplication] cancelLocalNotification:someNotification];
            }
    
        }
    }
    

提交回复
热议问题