Reputation: 517
I made an app that has custom notifications, but I cant remove them no matter what I do.
[[UIApplication sharedApplication] cancelLocalNotification:[idkey objectAtIndex:indexPath.row]];
That is the code I use for removal; If I use all it works. The idkey
is the correct
value, and its a number in a string, @"3"
in this case.
This is a part of the saving function:
-(void) addNewNotificationWithKey:(NSString*)key {
NSLog(@"%@",key);
Class cls = NSClassFromString(@"UILocalNotification");
if (cls != nil) {
UILocalNotification *notif = [[cls alloc] init];
notif.fireDate = [tempFormatter dateFromString:datuminura];
notif.timeZone = [NSTimeZone defaultTimeZone];
notif.alertBody = description1;
notif.alertAction = @"Open";
notif.soundName = UILocalNotificationDefaultSoundName;
Is it right?
Upvotes: 0
Views: 161
Reputation: 7504
Check which notification you want to remove and use following code to cancel it.
UIApplication *app = [UIApplication sharedApplication];
NSArray *eventArray = [app scheduledLocalNotifications];
for (int i=0; i<[eventArray count]; i++)
{
UILocalNotification* oneEvent = [eventArray objectAtIndex:i];
NSDictionary *userInfoCurrent = oneEvent.userInfo;
NSString *uid=[NSString stringWithFormat:@"%@",[userInfoCurrent valueForKey:@"uid"]];
if ([uid isEqualToString:uidtodelete])
{
//Cancelling local notification
[app cancelLocalNotification:oneEvent];
break;
}
}
[EDIT]
Add following line into your local notification to make [uid isEqualToString:uidtodelete] condition work.
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"%d",[idkey objectAtIndex:indexPath.row]] forKey:@"uid"];
notif.userInfo = infoDict;
Upvotes: 1