2013-04-14 36 views
1

我试图安排通知在上午7点交付。但它在上午12点交付。请帮助我做错了什么。这是我的代码。通知在凌晨12点递送,而不是上午7点

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点弹出。这里出了什么问题?

回答

1

我敢打赌localNotification.timeZonedf.timeZone是不一样的......

添加到您的DateFormatter:

df.timeZone = [NSTimeZone defaultTimeZone]; 
+0

没错。当我看到-5小时的差异时,似乎很明显。 – Sulthan

+0

这不会有帮助。 'NSDateFormatter'默认为当前时区。因此将其设置为默认时区是无操作的。 – rmaddy

+0

除非'defaultTimeZone'被设置为'localTimeZone'以外的其他东西? –

相关问题