Reputation: 2596
I have logged the local notification.
{fire date = Friday, April 18, 2014 at 9:00:00 PM India Standard Time, time zone = Asia/Kolkata (GMT+5:30) offset 19800, repeat interval = 0, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = Friday, April 18, 2014 at 9:00:00 PM India Standard Time, user info = { Key = ( "18/04/2014", "11:18:07", Tab, "Telma H", "80 mg", "1OD (Once a day)", "for 5 days", 5 ); }}
One can see that fire date is in "PM" but it is firing right away. I have scheduled it as below.
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"hh:mm a"];
[df setLocale:[NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]];
NSDate *dateToday = [NSDate date];
NSString *time = @"09:00 PM";
[df setDateFormat:@"yyyy-MM-dd "];
NSString *todayString = [df stringFromDate:[NSDate date]];
NSString *todaysTime = [todayString stringByAppendingString:time];
[df setDateFormat:@"yyyy-MM-dd hh:mm a"];
NSDate *date = [df dateFromString:todaysTime];
NSTimeInterval ti = [date timeIntervalSinceDate:dateToday];
[localNotification setFireDate:[dateToday dateByAddingTimeInterval:ti]];
[localNotification setTimeZone:[NSTimeZone defaultTimeZone]];
[localNotification setAlertBody:@"Local Notification" ];
[localNotification setAlertAction:@"Open App"];
[localNotification setHasAction:YES];
[localNotification setSoundName:UILocalNotificationDefaultSoundName];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
Upvotes: 0
Views: 611
Reputation: 2185
[localNotification setTimeZone:[NSTimeZone defaultTimeZone]];
This shows that time zone's is default which does not point to your time zone.
Upvotes: 1