UILocalNotification在我的设备中无效

时间:2013-02-15 10:53:42

标签: iphone ios ipad uilocalnotification

以下是我在应用程序中用于生成本地通知的代码:

 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

1 个答案:

答案 0 :(得分:0)