嘗試使用下面的代碼來安排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