通知无效

时间:2014-06-15 19:34:31

标签: ios objective-c

NSCalendar *lbCalendar = [[NSCalendar alloc]init];
NSDateComponents *dateComponent = [lbCalendar components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:[NSDate date]];

[dateComponent setYear:2014];
[dateComponent setMonth:6];
[dateComponent setDay:15];
[dateComponent setHour:22];
[dateComponent setMinute:29];

UIDatePicker *dp = [[UIDatePicker alloc]init];
[dp setDate:[lbCalendar dateFromComponents:dateComponent]];

UILocalNotification *notification = [[UILocalNotification alloc]init];
[notification setAlertBody:@"Hello Notification"];
[notification setFireDate:dp.date];
[notification setTimeZone:[NSTimeZone defaultTimeZone]];
[application setScheduledLocalNotifications:[NSArray arrayWithObject:notification]];

这是我在appdelegate.m中的代码,用于显示本地通知,但它无效,代码正确且没有错误,应用正在正确进行午餐,但未显示任何通知。

我使用Xcode 5.1和SDK 7.0

1 个答案:

答案 0 :(得分:0)

尝试使用

NSCalendar *lbCalendar = [NSCalendar currentCalendar];

而不是

NSCalendar *lbCalendar = [[NSCalendar alloc]init];