I’m having issues when trying to schedule a UILocalNotification using the following code:
- (IBAction) createNotification {
//Just to verify button called the method
NSLog(@"createNotification");
NSString *dateString = dateTextField.text;
NSString *textString = textTextField.text;
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MM-dd-yyyy HH:mm"];
[formatter setTimeZone: [NSTimeZone defaultTimeZone]];
NSDate *alertTime = [formatter dateFromString:dateString];
UIApplication *app = [UIApplication sharedApplication];
UILocalNotification *notification = [[[UILocalNotification alloc] init] autorelease];
if(notification){
notification.fireDate = alertTime;
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.repeatInterval = 0;
notification.alertBody = textString;
[app scheduleLocalNotification:notification];
NSLog(@"%@", dateString);
}
}
The code is being called correctly when I press the button and I’m passing in the following date string:
02-12-2012 19:01
- I’ve also tried
02/12/2012 19:01
to no avail. (I change the time accordingly depending on the time of testing e.g. 21:06)
Can someone please explain why the local notification isn’t displaying?
Thanks in advance,
Jack
Local notifications are delivered, but do not display (i.e., no badges, no sounds, no alerts) when the app is running and in the foreground. But the
application:didReceiveLocalNotification:method of your app delegate is called, if you need to react to a local notification in some way.See the UILocalNotification class reference for details.