Wednesday, January 23, 2013

LocalNotifications in iPhone



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [NSThread detachNewThreadSelector:@selector(fireLocalNotifications) toTarget:self withObject:nil];
 
}

-(void) fireLocalNotifications
{

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    for (int i = 0; i < 60; i++)
    {

        UILocalNotification *localNotification = [[UILocalNotification alloc] init];

        if (localNotification == nil){

            return;
}

        NSDate *notifyDate = [[NSDate date] dateByAddingTimeInterval:i * 60];

        localNotification.fireDate = notifyDate     
     
        localNotification.timeZone = [NSTimeZone defaultTimeZone];

        localNotification.alertBody = [NSString stringWithFormat:NSLocalizedString(@"This is local notification %i"), i];

        localNotification f.alertAction = NSLocalizedString(@"My Details", nil);

        localNotification.soundName = UILocalNotificationDefaultSoundName;

        localNotification.applicationIconBadgeNumber = 1;

        [[UIApplication sharedApplication] scheduleLocalNotification: localNotification];
       
        [localNotification release];

    }

    [pool release];
}

No comments:

Post a Comment