R3ptor
R3ptor

Reputation: 103

deactivate and activate a specific UILocalNotification

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

Upvotes: 1

Views: 45

Answers (1)

KrishnaCA
KrishnaCA

Reputation: 5695

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 :)

Upvotes: 3

Related Questions