Wednesday, May 22, 2013

scheduledLocalNotifications example UIApplication ios


[UIApplication scheduledLocalNotifications]

All currently scheduled local notifications.
@property(nonatomic, copy) NSArray *scheduledLocalNotifications
Discussion of [UIApplication scheduledLocalNotifications]
This property holds an array of UILocalNotification instances representing the current scheduled local notifications. You can set or reset the local notifications in the array as well as access them.
This method may be faster than using scheduleLocalNotification: when scheduling a large number of notifications.[UIApplication scheduledLocalNotifications]




Example of [UIApplication scheduledLocalNotifications]

NSMutableArray *notifications = [[NSMutableArray alloc] init];
[notifications addObject:notification];
app.scheduledLocalNotifications = notifications;
//Equivalent: [app setScheduledLocalNotifications:notifications];

Example of [UIApplication scheduledLocalNotifications]
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;
    }
}
Example of [UIApplication scheduledLocalNotifications]
NSArray *arrayOfLocalNotifications = [[UIApplication sharedApplication] scheduledLocalNotifications] ;

for (UILocalNotification *localNotification in arrayOfLocalNotifications) {

    if ([localNotification.alertBody isEqualToString:savedTitle]) {
        NSLog(@"the notification this is canceld is %@", localNotification.alertBody);

        [[UIApplication sharedApplication] cancelLocalNotification:localNotification] ; // delete the notification from the system

    }

}