2

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

如何将 NSDate 对象设置为格林威治标准时间上午 10:00?我问的原因是这个 - 我想设置一个本地通知在格林威治标准时间每天上午 10:00 发生。

我认为以下是正确的轨道:

    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];

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

4

1 回答 1

1

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

于 2011-01-05T11:41:12.757 回答