1

ローカル通知を生成するためにアプリケーションで使用したコードは次のとおりです。

 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
4

1 に答える 1

0

このチュートリアルをチェックしてください、それはあなたを助けるかもしれません。

http://www.theappcodeblog.com/2011/04/28/local-notifications-tutorial-add-a-local-notification-to-your-iphone-app/

于 2013-02-15T11:04:13.967 に答える