如果这绝对是菜鸟问题,我很抱歉,但我无法从文档或其他堆栈问题中找出这个问题 -

如何将 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];

不幸的是,这不会火。任何帮助将不胜感激 :)

有帮助吗?

解决方案

只要您的应用程序正在运行,通知就会直接发送到您的应用程序。您需要设置一个处理程序(在 appDelegate 中)并自行显示消息。当应用程序未运行时,应显示通知。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top