这是我在应用程序中用于生成本地通知的代码:
UILocalNotification *aNotification = [[UILocalNotification alloc] init];
if (aNotification == nil)
{
NSLog(@"localNotif");
return;
}
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSTimeZone *sourceTimeZone = [NSTimeZone timeZoneForSecondsFromGMT:19800];
[dateFormatter setTimeZone:sourceTimeZone];
NSDate *sourceDate = [dateFormatter dateFromString:@"2013-02-16 15:00:00"];
NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone];
NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:sourceDate];
NSTimeInterval interval = destinationGMTOffset;
NSDate* destinationDate = [[NSDate alloc] initWithTimeInterval:interval sinceDate:sourceDate];
aNotification.fireDate = destinationDate;
aNotification.timeZone = [NSTimeZone defaultTimeZone];
NSLog(@"destinationDate %@",destinationDate);
aNotification.alertBody = @"About To Start";
aNotification.alertAction = @"View";
[[UIApplication sharedApplication] scheduleLocalNotification:aNotification];
[dateFormatter release];
[destinationDate release];
[aNotification release];
但是当我通过从设置应用程序更改日期和时间在设备中对其进行测试时,该事件没有触发。我究竟做错了什么?
当我在控制台中打印destinationDate
时,它是这样的:
destinationDate 2013-02-16 15:00:00 +0000