1

我正在尝试安排在早上 7 点发送通知。但它在上午 12 点交付。请帮助我做错了什么。这是我的代码。

NSString *date = @"4/14/2013 07:00";
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"MM/dd/yyyy HH:mm"];
NSDate *thisDate = [df dateFromString:date];

UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = thisDate;
localNotification.timeZone = [NSTimeZone defaultTimeZone];  
localNotification.alertBody = @"This is notification";
localNotification.alertAction = @"view";
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.alertLaunchImage = Nil;
self.badgeCount ++;
localNotification.applicationIconBadgeNumber = self.badgeCount;
localNotification.userInfo = Nil;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

我预计此通知将在上午 7 点送达。相反,它在上午 12 点弹出。这里出了什么问题?

4

1 回答 1

1

我打赌localNotification.timeZonedf.timeZone不一样...

将此添加到您的 DateFormatter:

df.timeZone = [NSTimeZone defaultTimeZone];
于 2013-04-14T21:41:40.013 回答