簡體   English   中英

通知無效

[英]Notification not working

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一起使用

嘗試使用

NSCalendar *lbCalendar = [NSCalendar currentCalendar];

代替

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM