我正在尝试设置UILocalNotification
,但它没有按时开火。它会在2小时后发射然后应该发射。这是我如何计算提醒日期:
NSDate *etkinlikDate = [gregorian dateFromComponents: components];
sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
destinationTimeZone = [NSTimeZone systemTimeZone];
sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:etkinlikDate];
destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:etkinlikDate];
interval = destinationGMTOffset - sourceGMTOffset;
etkinlikDate = [[NSDate alloc] initWithTimeInterval:interval sinceDate:etkinlikDate];
此处etkinlikDate
会返回正确的值。 (我想发布通知的日期)
以及我如何设置警报:
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.fireDate = etkinlikDate;
localNotification.alertBody = [NSString stringWithFormat: @"%@ %@", [sClass className], etkinlikSaati];
localNotification.soundName = @"receivedmessage.caf";
localNotification.alertAction = @"Show me the item %d";
localNotification.timeZone = [NSTimeZone systemTimeZone];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
// Request to reload table view data
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadData" object:self];
虽然正确设置了etkinlikDate,但本地通知未按时触发。
更新:让我们说我想在16:30设置警报。
etkinlikDate返回16:30,但在18:30发出警报。