ここでアラームを設定しようとしています。私はモントリオールにいるので、EST タイムゾーンにいます。私が使用しているコードでは、現在の日付を取得し、数分後に鳴らそうとします。コードは完全に正常に機能し、期待どおりにアラームが鳴ります。
問題は次のとおりです。現在、午前 12 時 41 分です。アラームは 12.43 に鳴ります。ただし、私の NSLog では、時刻が出力されます: fireDate : 2012-02-16 17:43:00 +0000
それは機能するので大きな問題ではありませんが、なぜそれがその時点で表示されていて、まだ機能しているのかについて何か考えはありますか? それを修正する方法について何か考えはありますか?ありがとう!
私は基本的にタイムゾーンをどこにでも置きます。ここに私が使用しているコードがあります:
-(void)scheduleNotificationWithInterval:(int)minutesBefore {
// Current date NSDate *now = [NSDate date]; // Specify which units we would like to use unsigned units = NSTimeZoneCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit; NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSTimeZone* zone = [NSTimeZone timeZoneWithName:@"EST"]; [calendar setTimeZone:zone]; NSDateComponents *components = [calendar components:units fromDate:now]; [components setTimeZone:[NSTimeZone timeZoneWithName:@"EST"]]; NSInteger year = [components year]; NSInteger month = [components month]; NSInteger day = [components day]; NSInteger hour = [components hour]; NSInteger minute = [components minute]; NSDateComponents *dateComps = [[NSDateComponents alloc] init]; [dateComps setYear:year]; [dateComps setMonth:month]; [dateComps setDay:day]; [dateComps setHour:hour]; [dateComps setMinute:minute+2]; // Temporary NSDate *itemDate = [calendar dateFromComponents:dateComps]; NSLog(@"fireDate : %@", itemDate); UILocalNotification *localNotif = [[UILocalNotification alloc] init]; if (localNotif == nil) return; localNotif.fireDate = itemDate; //localNotif.timeZone = zone; localNotif.timeZone = [NSTimeZone timeZoneWithName:@"EST"]; minutesBefore = 15; // Temporary localNotif.alertBody = [NSString stringWithFormat:NSLocalizedString(@"%@ in %i minutes.", nil), @"Blabla", minutesBefore]; localNotif.alertAction = NSLocalizedString(@"See Foo", nil); localNotif.soundName = UILocalNotificationDefaultSoundName; NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"LastCall" forKey:@"lastcall"]; localNotif.userInfo = infoDict; [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}
ありがとう!