UILocalNotification 安排重复 10AM GMT 问题
如果这绝对是菜鸟问题,我很抱歉,但我无法从文档或其他堆栈问题中弄清楚这个问题 -
如何将 NSDate 对象设置为 10:00AM GMT?我问的原因是这样的 - 我想将本地通知设置为每天上午 10:00 GMT。
我认为以下内容是正确的:
NSDateComponents *comps = [[NSDateComponents alloc]init];
[comps setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
[comps setYear:2011];
[comps setMonth:1];
[comps setWeek:1];
[comps setDay:1];
[comps setHour:10];
[comps setMinute:52];
[comps setSecond:0];
NSCalendar *gregorian = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *date = [gregorian dateFromComponents:comps];
[comps release];
UILocalNotification *notif = [[UILocalNotification alloc]init];
notif.fireDate = date;
notif.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];
notif.alertBody = @"New Challenges are available in Halo: Reach.\n\n Give them a look over with Halo Reach Challenges!";
notif.alertAction = @"Show Me";
notif.applicationIconBadgeNumber = 5;
notif.repeatInterval = NSDayCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
[notif release];
不幸的是,这不会触发。任何帮助将不胜感激:)
I'm sorry if this is an absolute noob question, but I can't figure this one out from the documentation or other stack questions -
How can I set an NSDate object to 10:00AM GMT? The reason I ask is this - I want to set a localnotification to occur at 10:00AM GMT every day.
I think the following is on the right track:
NSDateComponents *comps = [[NSDateComponents alloc]init];
[comps setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
[comps setYear:2011];
[comps setMonth:1];
[comps setWeek:1];
[comps setDay:1];
[comps setHour:10];
[comps setMinute:52];
[comps setSecond:0];
NSCalendar *gregorian = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *date = [gregorian dateFromComponents:comps];
[comps release];
UILocalNotification *notif = [[UILocalNotification alloc]init];
notif.fireDate = date;
notif.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];
notif.alertBody = @"New Challenges are available in Halo: Reach.\n\n Give them a look over with Halo Reach Challenges!";
notif.alertAction = @"Show Me";
notif.applicationIconBadgeNumber = 5;
notif.repeatInterval = NSDayCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
[notif release];
Unfortunately, this doesn't fire. Any help would be greatly appreciated :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只要您的应用程序正在运行,通知就会直接发送到您的应用程序。您需要设置一个处理程序(在 appDelegate 中)并自行显示消息。当应用程序未运行时,应显示通知。
As long as your app is running, the notification is sent directly to your app. You'll need to set up a handler (in appDelegate) and the display the message yourself. When the app is not running, the notification should be shown.