2013-04-14 44 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'以外的其他東西? –

相關問題