Multiple Local Notification in iPhone

In my app, I have list of friends say: 3 friends, all these three have birthday details. I need to schedule local notification to show their b’days alert. I know and handled a local notification but how will I handle these multiple notification?

I am setting fire date in "for loop”.Is it proper, See the code.

UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
        return;
    NSDateFormatter *formatter = [[[NSDateFormatter alloc]init]autorelease];
    for (int i = 0; i< [delegate.viewController.contactList count] ; i++) {
        NSString *birthday = [[myArray objectAtIndex:i]objectForKey:@"birthday"];

        [formatter setDateFormat:@"MM/dd/yyyy"];
        NSDate *date = [formatter dateFromString:birthday];

        localNotif.fireDate = [date dateByAddingTimeInterval:10];
        localNotif.timeZone = [NSTimeZone defaultTimeZone];
        NSLog(@"local %@",localNotif.fireDate);
    }

    localNotif.applicationIconBadgeNumber = 1;

    NSString *itemName = @“Friend Name";
    NSDictionary *userDict = [NSDictionary dictionaryWithObjectAndKey:itemName,@"msg", nil];

    localNotif.userInfo = userDict;
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
    [localNotif release];

What I want,in this method only I have to set notification for all the friend based on their date. can any one tell me where I’m doing wrong and if I’m missing anything please inform me.

Answers


Just make three (or more) local notifications and schedule every one of them with scheduleLocalNotification:, what's the problem? For example this is what I did in my project:

for (int i = 0; i < 6; i++) {
    UILocalNotification *localNotification = [prototypeNotification copy];
    localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:dates];
    [notifications addObject:localNotification];


    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

    [localNotification release];
}

UPD

// ...this goes earlier:
static NotificationController *sharedNotificationController = nil;

- (id) init 
{
    if (self = [super init]) {
        notifications = [[NSMutableArray alloc] init];

        prototypeNotification = [[UILocalNotification alloc] init];
        prototypeNotification.repeatCalendar = [NSCalendar currentCalendar];
        prototypeNotification.repeatInterval = NSMinuteCalendarUnit;

        prototypeNotification.timeZone = [NSTimeZone defaultTimeZone];
        prototypeNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:0];
        prototypeNotification.applicationIconBadgeNumber = 0;
        prototypeNotification.alertBody = NSLocalizedString(@"Body", nil);
        prototypeNotification.alertAction = NSLocalizedString(@"Action", nil);

        enabled_ = NO;
    }
    return self;
}

Need Your Help

How to get all phone numbers with labels for all contacts in address book?

iphone objective-c ios abaddressbook addressbookui

I want to get all the phone numbers with diff labels like "iPhone", "home phone", "mobile number", "other numbers" , etc. for a contact stored in iPhone address book.

How do I create a loop based off this array?

php input foreach

I'm trying to process this array, first testing for the presence of a check, then extrapolating the data from quantity to return a valid price.