Jac*_*ins 3 iphone objective-c 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);
}
}
Run Code Online (Sandbox Code Playgroud)
当我按下按钮并且我传入以下日期字符串时,正确调用代码:
02-12-2012 19:01
02/12/2012 19:01
无济于事.(我根据测试时间相应地改变时间,例如21:06)
有人可以解释为什么没有显示本地通知?
提前致谢,
插口
yuj*_*uji 10
提供本地通知,但在应用程序运行和前台时不显示(即没有徽章,没有声音,没有警报).但是application:didReceiveLocalNotification:,如果您需要以某种方式对本地通知做出反应,则会调用您的应用委托的方法.
有关详细信息,请参阅UILocalNotification类参考.
| 归档时间: |
|
| 查看次数: |
3770 次 |
| 最近记录: |