Search code examples
iosuicollectionviewuilocalnotification

deactivate and activate a specific UILocalNotification


What do I have to do that I can cancel a specific UILocalNotification?


Solution

  • I believe you are looking a way to cancel specific local notification. If that is what you are looking for, this might help you.

    The following is the code for cancelling a local notification.

    [[UIApplication sharedApplication] cancelLocalNotification:localNotification]
    

    For identifying the specific UILocalNotification if your notification is not global.

    for (UILocalNotification *localNotification in [[UIApplication sharedApplication] scheduledLocalNotifications])
    {
        NSDictionary* userInfo = localNotification.userInfo;
        if ([[userInfo objectForKey:@"name"] isEqualToString:@"NAME_OF_NOTIFICATION"]) {
            [[UIApplication sharedApplication] cancelLocalNotification:localNotification];
            break;
        }
    }
    

    Here, I used UILocalNotifications userinfo to identify the specific UILocalNotification. You can use other things like alertTitle etc. to identify different UILocalNotifications

    Hope it helps :)