简体   繁体   English

iOS离线时特定TimeZone的“实时”时间

[英]iOS “real” time for specific TimeZone while offline

This is the scenario: 这是场景:

I'm writing a medical related program, that would be use while with no connection. 我正在编写一个医学相关的程序,可以在没有连接的情况下使用。 When some action act, the program would write the time to CoreData record. 当某个动作动作时,程序会将时间写入CoreData记录。

That's the problem, if their device set the time to a diff time like earlier than the real time. 这就是问题,如果他们的设备将时间设置为比实时更早的差异时间。 That would be a big problem coz it's for medical usage. 这将是一个很大的问题,因为它用于医疗用途。

  • So, how can i get the "real" time even if there is no connection? 那么,即使没有连接,我怎样才能获得“真实”的时间?
  • Or, is it possible to disallow user changing the device time using something like restrictions or DeviceProfile? 或者,是否可以禁止用户使用限制或DeviceProfile等更改设备时间?

It's only because Apple IS the Big Brother they claimed to be fighting in 1984. Welcome to 1984! 这只是因为Apple是他们声称在1984年战斗的老大哥。欢迎来到1984年! Otherwise we would have access to real time time, and an English version of ISO date format! 否则我们可以访问实时时间和ISO日期格式的英文版本! :-/ Every iPwn, and now other devices, has a GPS receiver and an Internet capability, from which sub-second accurate time could be derived, yet Apple insists on forcing us to depend on AT&T to automatically set our clocks. : - /每个iPwn,现在其他设备都有GPS接收器和互联网功能,可以从中获得亚秒级的准确时间,但Apple坚持强迫我们依靠AT&T自动设置我们的时钟。 It's only recently that AT&T started delivering accurate time, thank god for small favors. 直到最近AT&T开始提供准确的时间,感谢上帝的小恩惠。

The lack of GPS and NTP time setting, plus the glaring omission of ISO 8601 date formatting with otherwise USA formats and language, is extremely annoying on a daily basis. 缺乏GPS和NTP时间设置,加上明确省略ISO 8601日期格式以及其他美国格式和语言,每天都非常烦人。

So, the answer to your question is, Yes, it is feasible, but not in Apple's Jail, since you cannot set RTC from GPS or NTP without jail breaking. 所以,你的问题的答案是,是的,它是可行的,但不是Apple的Jail,因为你不能在没有越狱的情况下从GPS或NTP设置RTC。

PS: my guess is that AT&T insists on this for call-timing or something stupid that has to do with charging us more money! PS:我的猜测是,AT&T坚持这个用于通话时间或与我们收取更多钱有关的愚蠢行为! ;-) ;-)

You get the real time from [NSDate date]. 您可以从[NSDate日期]获得实时。 For example, the following: 例如,以下内容:

[[NSDate date] timeIntervalSince1970]

gives the number of seconds since 1/1/1970 midnight UTC. 给出自1970年1月1日UTC午夜以来的秒数。 This is independent of timezone and independent of whatever time is set by the user. 这与时区无关,并且与用户设置的时间无关。 If you know the timezone, then you can convert that to local time with the NSDateFormatter if you like, but make sure to also record the timezone to make the representation unique. 如果您知道时区,那么您可以使用NSDateFormatter将其转换为本地时间(如果您愿意),但请确保还记录时区以使表示具有唯一性。

EDIT: Sorry, this answer is actually not correct. 编辑:对不起,这个答案实际上是不正确的。 After trying it out, it appears that setting the time by the user also changes the NSDate values. 尝试后,用户设置时间似乎也会更改NSDate值。

So, how can i get the "real" time even if there is no connection? 那么,即使没有连接,我怎样才能获得“真实”的时间?

If by "no connection" you mean "no network connection of any sort" the answer is that you can't. 如果通过“无连接”你的意思是“没有任何类型的网络连接”,答案就是你不能。

I think the best you can do is disable the functionality if you can't find a way to independently verify the system time (and tell the user why). 我认为,如果您无法找到独立验证系统时间的方法(并告诉用户原因),您可以做的最好是禁用该功能。

NSDate and all associated classes read the date from the system time. NSDate和所有关联的类从系统时间读取日期。 Without an internet connection to refer to, the NSDate class is open to user abuse. 如果没有要引用的Internet连接,NSDate类对用户滥用是开放的。

I used an example in a comment on fishinear's answer of Farmville. 我在一个关于fishinear对Farmville的回答的评论中使用了一个例子。 If the user plants some crops that take five hours to grow, you can just change the system time to five hours in the future to harvest. 如果用户种植一些需要5个小时才能生长的作物,您可以将系统时间改为未来5个小时来收获。 Which, I'm sure, is one of the reasons that Zynga requires an internet connection to play their games. 我敢肯定,这是Zynga需要互联网连接才能玩游戏的原因之一。

Without some time-telling hardware, Apple cannot realistically tell time without an internet connection; 如果没有一些具有时间知识的硬件,苹果无法在没有互联网连接的情况下实际告知时间 even if they did have some amazing solution, they'd have to take into account timezones and even travel across timezones in order to make this work. 即使他们确实有一些惊人的解决方案,他们也必须考虑时区,甚至跨时区旅行才能使这项工作成功。

If I were you, I'd require an internet connection at specified intervals (once a day or the like) in order to draw a reference. 如果我是你,我需要按指定的时间间隔(每天一次等)连接互联网,以便绘制参考。

Let us know why you need this and we may be able to suggest some viable alternatives in function. 让我们知道您为什么需要这个,我们可以在功能上建议一些可行的替代方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM