How to Create UILocalNotification, repeating every minute ?

H

There are two types of notifications in iOS, One is Local notification & other is PUsh notification. Added code to create Local notification.

// creating notification
NSDate *newDate = [NSDate dateWithTimeIntervalSinceNow:60];

// where 60 = seconds, so add your seconds here
Class cls = NSClassFromString(@”UILocalNotification”);
if (cls != nil) {
UILocalNotification *notification = [[cls alloc] init];
notification.fireDate = newDate;
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.alertBody = @“My Notification”;
notification.alertAction = @”Show me”;
notification.soundName = UILocalNotificationDefaultSoundName;
notification.applicationIconBadgeNumber = 1;
notification.repeatInterval = NSMinuteCalendarUnit;
NSString *str = @“String to pass”;
NSDictionary *userDict = [NSDictionary dictionaryWithObject:str forKey:@“myNotification”];
notification.userInfo = userDict;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
[notification release];
}

// receiving notification
– (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
NSLog(@”Notification: %@”, [notification.userInfo objectForKey:@“myNotification”]);
}

About the author

surjit.joshi
By surjit.joshi

Category