Question

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 :)

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top