I want to setup local notification for a specific EST time, and user should get the notification irrespective of user’s default timezone. lets say, if I want the local notification to arrive at 12:00 noon EST, then some one in pacific timezone should also get the notification when it is 12:00 noon est which is 09:00 PST
here is what I have tried to do, but I only get notifications when I set my default timezone to EST
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.repeatInterval = kCFCalendarUnitDay;
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
NSDate *today = [NSDate date];
NSDateComponents *dateComponents = [calendar components:( NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit )
fromDate:today];
NSDateComponents *dateComps = [[NSDateComponents alloc] init];
[dateComps setDay:dateComponents.day];
[dateComps setMonth:dateComponents.month];
[dateComps setYear:dateComponents.year];
[dateComps setHour:12];
[dateComps setMinute:00];
[dateComps setSecond:00];
NSDate *fireDate = [calendar dateFromComponents:dateComps];
localNotif.fireDate = fireDate;
localNotif.timeZone = [NSTimeZone timeZoneWithName:@"US/Eastern"];
localNotif.alertBody = @"Daily Notification";
localNotif.alertAction = NSLocalizedString(@"View", nil);
localNotif.soundName = UILocalNotificationDefaultSoundName;
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"Daily Notification" forKey:@"acme"];
localNotif.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
can someone tell me where am I going wrong.
I have found out the issue here.. Time zone should be set for the date and not for the notification, so I would have to add this line of code:
and should comment the code line: