iOS “real” time for specific TimeZone while offlin

2019-08-04 00:32发布

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.

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?

4条回答
该账号已被封号
2楼-- · 2019-08-04 00:53

It's only because Apple IS the Big Brother they claimed to be fighting in 1984. Welcome to 1984! Otherwise we would have access to real time time, and an English version of ISO date format! :-/ 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. It's only recently that AT&T started delivering accurate time, thank god for small favors.

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.

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.

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! ;-)

查看更多
狗以群分
3楼-- · 2019-08-04 00:53

You get the real time from [NSDate date]. For example, the following:

[[NSDate date] timeIntervalSince1970]

gives the number of seconds since 1/1/1970 midnight 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.

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.

查看更多
神经病院院长
4楼-- · 2019-08-04 00:59

NSDate and all associated classes read the date from the system time. Without an internet connection to refer to, the NSDate class is open to user abuse.

I used an example in a comment on fishinear's answer of 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. Which, I'm sure, is one of the reasons that Zynga requires an internet connection to play their games.

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.

查看更多
迷人小祖宗
5楼-- · 2019-08-04 01:04

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).

查看更多
登录 后发表回答