ここでアラームを設定しようとしています。私はモントリオールにありますので、ESTタイムゾーンにあります。 私が使用しているコードでは、現在の日付を取得して、それを数分後に呼び出します。 コードは正常に動作し、アラームは期待どおりに鳴ります。UILocalNotification&NSTimeZone、タイムゾーンが正しく表示されない
ここが問題です:今は12.41です。アラームは12.43で鳴ります。 しかし、私のNSLogで、時間が出力されます。fireDate:2012-02-16夜05時43分00秒0000
それはそれが動作するので、大きな問題ではないのですが、なぜそれがで表示されて上の任意のアイデアその時、まだ動作しますか?どのようにそれを修正する上で任意のアイデア?ありがとう! (空)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];
}
、ここで私が使用していたコードですありがとう!
私は+0000についてはわかりませんでした。しかし、私は_dateComps.timeZone = [NSTimeZone timeZoneWithName:@ "EST"]を追加しました。dateComps initの直後に_まだ取得しました** fireDate:2012-02-16 18:07:00 + 0000 ** –
申し訳ありません、EST有効な名前ではありません。 "America/Montreal"(解答で編集)を試してみてください。 [NSTimeZone knownTimeZoneNames]を使用して有効な名前の配列を取得できます。 – MGA
便利です! [NSTimeZone knownTimeZoneNames]を使って見つかったものをどこにコピーして貼り付けたのですか?しかし、私は奇妙なことに+0000を持っています。私はすべての変数を設定する前にsetTimeZonesを移動し、それでも取得します! –