为什么当地通知在开火日期之前被解雇?

时间:2014-04-18 05:54:09

标签: ios uilocalnotification

我已记录本地通知。

{起火日期= 2014年4月18日星期五下午9:00:00印度标准时间,时区=亚洲/加尔各答(格林威治标准时间+5:30)偏移19800,重复间隔= 0,重复计数= UILocalNotificationInfiniteRepeatCount,下一次开火日期= 2014年4月18日星期五下午9:00:00印度标准时间,用户信息= {     键=(         “18/04/2014”,         “11时18分07秒”,         标签,         “Telma H”,         “80毫克”,         “10D(每天一次)”,         “连续5天”,         五     ); }}

人们可以看到火灾日期在“PM”,但它立即开火。我安排如下。

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

1 个答案:

答案 0 :(得分:1)

[localNotification setTimeZone:[NSTimeZone defaultTimeZone]];

这表示时区是默认值,不指向您的时区。

相关问题