开发者

Delete LocalNotification

I set a local not开发者_如何学Cification with key "notify" and know that i can delete it with below code but don't know how to declare 'notification' for key "notify" to delete it

[[UIApplication sharedApplication] cancelLocalNotification:notification];


UILocalNotification implements the NSCoding protocol, so you could archive the notification and store it somewhere for the time that it didn't fired. When you need to cancel the notification, just iterate over your saved ones and look for the one with the name "notify".


You could find a great answer at Cancel UILocalNotification

I extracted the code from there

 NSString *myIDToCancel = @"some_id_to_cancel";
UILocalNotification *notificationToCancel=nil;
for(UILocalNotification *aNotif in [[UIApplication sharedApplication] scheduledLocalNotifications]) {
  if([aNotif.userInfo objectForKey:@"ID"] isEqualToString:myIDToCancel]) {
     notificationToCancel=aNotif;
     break;
  }
}
[[UIApplication sharedApplication] cancelLocalNotification:notificationToCancel];


I tried to cancel the notification using:

[[UIApplication sharedApplication] cancelLocalNotification:notificationToCancel];

But this doesn't remove the notification from the notification center. And the application don't save all the notifications, this method:

[[UIApplication sharedApplication] scheduledLocalNotifications];

Return only notification with the property: "repeatInterval" distinct of nil.

If you want to schedule a notification and add it to that retrieved notifications, you need to put a high repeatInterval like a year and cancel it when its clicked!

I hope its helpfull and sorry for my inglish!!!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜