我剛剛在iOS 6.1.3上運行了一些測試。這是我得到的:
我在西雅圖,在下午1:00(太平洋夏令時,格林威治標準時間-7)。我創建了一個NSDate
:
NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
// 2013-08-31 @ 12:00:00 (noon)
dateComponents.year = 2013;
dateComponents.month = 8;
dateComponents.day = 31;
dateComponents.hour = 12;
dateComponents.minute = 0;
dateComponents.second = 0;
NSDate *fireDate = [gregorianCalendar dateFromComponents:dateComponents];
現在我有
fireDate = 2013-08-31 19:00:00 +0000 (2013-08-31 12:00:00 -0700)
然後我創建並安排通知:西雅圖(太平洋夏令時剛剛創建的通知
notification1 = [[UILocalNotification alloc] init];
notification1.fireDate = fireDate;
// notification1.timeZone is nil by default
NSLog(@"%@", notification1);
notification2 = [[UILocalNotification alloc] init];
notification2.fireDate = fireDate;
notification2.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
NSLog(@"%@", notification2);
notification3 = [[UILocalNotification alloc] init];
notification3.fireDate = fireDate;
notification3.timeZone = [NSTimeZone defaultTimeZone];
NSLog(@"%@", notification3);
日誌, ,GMT-7):
notification1:
fire date = Saturday, August 31, 2013, 12:00:00 PM Pacific Daylight Time,
time zone = (null),
next fire date = Saturday, August 31, 2013, 12:00:00 PM Pacific Daylight Time
notification2:
fire date = Saturday, August 31, 2013, 7:00:00 PM GMT,
time zone = GMT (GMT) offset 0,
next fire date = Saturday, August 31, 2013, 7:00:00 PM Pacific Daylight Time
notification3:
fire date = Saturday, August 31, 2013, 12:00:00 PM Pacific Daylight Time,
time zone = US/Pacific (PDT) offset -25200 (Daylight),
next fire date = Saturday, August 31, 2013, 12:00:00 PM Pacific Daylight Time
我將電話的時區更改爲芝加哥,現在是下午3點(中央夏令時間,格林威治標準時間-5)。
日誌的通知,在芝加哥(中部夏令時間,GMT-5)
notification1:
fire date = Saturday, August 31, 2013, 2:00:00 PM Central Daylight Time,
time zone = (null),
next fire date = Saturday, August 31, 2013, 2:00:00 PM Central Daylight Time
notification2:
fire date = Saturday, August 31, 2013, 7:00:00 PM GMT,
time zone = GMT (GMT) offset 0,
next fire date = Saturday, August 31, 2013, 7:00:00 PM Central Daylight Time
notification3:
fire date = Saturday, August 31, 2013, 12:00:00 PM Pacific Daylight Time,
time zone = US/Pacific (PDT) offset -25200 (Daylight),
next fire date = Saturday, August 31, 2013, 12:00:00 PM Central Daylight Time
結論:
- 當UILocalNotification
timeZone
是零,火日期是固定的時間。這意味着通知將在GMT格林威治標準時間下午12:00,格林威治標準時間下午2點或格林威治標準時間下午7點發射。
- 當UILocalNotification
timeZone
設置爲GMT時,計算GMT時間的啓動日期,並且如果用戶轉到其他時區,則會自動更新。在這個例子中,格林尼治標準時間-7點的時間被轉換爲格林尼治標準時間19點,並且通知被設置爲當地時間19點,無論我們在哪個時區(格林威治標準時間19點,格林威治標準時間5點19分或格林威治標準時間19:00)。
- 當UILocalNotification
timeZone
設置爲當地時區(太平洋夏令時,格林威治標準時間-7)時,計算當地時間的火災日期,如果用戶轉到其他時區,則會自動更新火災日期。在這個例子中,時間是格林威治標準時間-7點,因此無論我們在哪個時區(格林威治標準時間12:00,格林威治標準時間-5點或格林威治標準時間12:00),當地時間12:00通知您。 7)。
太棒了。從技術上講,你預定這個時間是格林尼治時間7PM而不是中午,但它也回答了這個問題。 –
有沒有人對iOS 10中的UNNotification觸發日期進行過類似的調查? – Jonny
@Jonny我也想知道。看來設置時區沒有任何區別。 – David