尝试使用下面的代码来安排UILocalNotification时碰到的问题:UILocalNotification - 通知不显示
- (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);
}
}
代码的调用是否正确,当我按下按钮,我传递以下日期字符串:
2012年2月12日19:01
- 我也试过
02/12/2012 19:01
无济于事。 (相应地根据测试时间改变时间,例如21:06)
有人可以解释为什么本地通知不显示吗?
由于提前,
杰克
当你执行NSLog(@“%@”,alertTime)'时会发生什么? – yuji 2012-02-12 20:13:47
你可以尝试以下代码来使用presentLocalNotificationNow替换scheduleLocalNotification以确保本地通知正常工作吗?你正在使用哪个iOS版本? – Allen 2012-02-12 20:14:35
您是否尝试过NSLog notification.fireDate以查看它显示的时间? – Shubhank 2012-02-12 20:16:49