Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obtaining a list of existing UILocalNotifications and modifying their dates

I'm trying to schedule several UILocalNotifications, and I need to have access to the already created notifications.

Is it possible to have a list/array of all the UILocalNotifications created? Can I edit the fire date of an existing local notification?

This is the code I use for creating local notifications:

 UILocalNotification* localNotification = [[UILocalNotification alloc] init];
 localNotification.fireDate = pickerDate;
 localNotification.alertBody = textFieldName.text;
 localNotification.alertAction = @"Item date expired!";
 localNotification.timeZone = [NSTimeZone defaultTimeZone];
 localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
like image 824
Bruno Avatar asked Jul 29 '13 12:07

Bruno


3 Answers

you can get all UILocalNotifications with below code

UIApplication* objApp = [UIApplication sharedApplication];
NSArray*    oldNotifications = [objApp scheduledLocalNotifications];

and also you can cancel that Notification with bellow code..

if ([oldNotifications count] > 0)
    [objApp cancelAllLocalNotifications];

Also see one basic demo with tutorial for UILocalNotification from below link

iphone-programming-tutorial-local-notifications

like image 190
Paras Joshi Avatar answered Oct 18 '22 21:10

Paras Joshi


to retrieve current notifications

NSArray *currentNotifications = [[UIApplication sharedApplication] scheduledLocalNotifications];

edit the content of this array (you might have to create a mutable copy first) and then set it back using

[[UIApplication sharedApplication] setScheduledLocalNotifications:myNotifications];

myNotifications containing both the old pending notifications and your new ones, it will override the old values, so by editing the fireDate of the UILocalNotification objects in this array you can change the date they will be fired at.

like image 6
Jerome Diaz Avatar answered Oct 18 '22 22:10

Jerome Diaz


I think you want this.

[[UIApplication sharedApplication] scheduledLocalNotifications]
like image 4
iNeal Avatar answered Oct 18 '22 20:10

iNeal