TheLearner
TheLearner

Reputation: 19507

UILocalNotification not using the correct timezone

I am configuring my UILocalNotification to use the default timezone i.e. the one in settings of the iPhone i.e. the time that appears on the iPhone's clock however it keeps using greenwich time. Any ideas?

//This method gets called every time the user changes the event date:

- (void)rescheduleNotification {
    [[UIApplication sharedApplication] cancelAllLocalNotifications];

    //create new one using interval
    UILocalNotification *localNotification = [[UILocalNotification alloc]init];

    localNotification.timeZone = [NSTimeZone defaultTimeZone];
    localNotification.fireDate = [self.currentSetting.lessonStartDate dateWithOffsetMinutes:[self.currentSetting.lessonRemindMinutes intValue]];

    NSLog(@"locationNotificated scheduled for %@", localNotification.fireDate);

    localNotification.repeatInterval = NSWeekCalendarUnit;
    localNotification.alertAction = nil;
    localNotification.alertBody = @"due to begin shortly";
    localNotification.hasAction = YES;
    localNotification.soundName = UILocalNotificationDefaultSoundName;


    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

    [localNotification release];

}

Upvotes: 0

Views: 942

Answers (2)

Hox
Hox

Reputation: 630

[NSTimeZone defaultTimeZone] is not timezone set in phone preferences, for this You should use

localNotification.timeZone = [NSTimeZone systemTimeZone];

Upvotes: 0

rckoenes
rckoenes

Reputation: 69469

All NSDate objects when they are printen will use GMT.

So you NSLog statement will always display something with the +0000 timezone.

Example:

if you set the date to 15:00 and your time zone is +0500 then when you print the date it will say: 10:00 since the offset is +0500

Upvotes: 1

Related Questions