0

私は通知を設定しています、私はそれを設定するために使用するNSDateがそれであることがわかりますが、通知を設定する2012-10-10 08:37:55 +0000 と起動する別の日付をNSLogにします:

 Notification will be shown on: 2011-10-10 08:37:55 +0000

コードは次のとおりです。

NSLog(@"mode:%d",[memoryInstance getEditMode]);
NSLog(@"schedule for sound:%@",number);
NSLog(@"DATE :%@",self.date); //different from the one comes next

UILocalNotification *localNotification = [[UILocalNotification alloc] init];

   NSDateFormatter *dateFormat =  [[[NSDateFormatter alloc]init] autorelease]  ;
 [dateFormat setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
 NSString *dateString = [dateFormat stringFromDate:self.date]; //!!
 NSDate *notificationDate = [dateFormat dateFromString:dateString];



localNotification.fireDate = notificationDate;
NSLog(@"Notification will be shown on: %@",localNotification.fireDate); //different!

localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.alertBody = [NSString stringWithFormat:
                               @"You have something to do.."];
localNotification.alertAction = NSLocalizedString(@"View details", nil);

NSDictionary *userInfo = [NSDictionary dictionaryWithObject:number forKey:kTimerNameKey];
localNotification.userInfo=userInfo;

localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.applicationIconBadgeNumber =-1;

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

何が起こるかというと、設定した瞬間に通知が来るということです。それは過去のことです。

4

1 に答える 1

0

とった。フォーマッタに yyyy を使用する必要がありました。YYYY は週数です。

于 2012-10-10T08:52:44.397 に答える