5

I recently found a library called TrueTime for getting the time which does not depend on device time. It uses NTP to get the time.

https://github.com/instacart/TrueTime.swift

As this library is primarily built for swift 3. But I found a post in which there were some changes made in files to make it swift 4 compatible.

https://github.com/instacart/TrueTime.swift/issues/39

As I am using swift & using pod for this library. I unlocked the pods & made changes in the library to make work with swift 4.

How reliable is this library?

My concerns are

  1. Apple approval after submitting an app.

  2. Support for coming swift & iOS versions.

Are there better alternatives to this library?

Kiran Sarvaiya
  • 1,318
  • 1
  • 13
  • 37
TechChain
  • 8,404
  • 29
  • 103
  • 228
  • 3
    NTP is a standard network protocol. Why would Apple have an issue with an app that uses NTP? The risk with any 3rd party code is that you either depend on the code's maintainer or you take on maintenance yourself. No one here can tell you whether the risk is acceptable; you have to balance the risk vs the cost of building your own code from the ground up. – Paulw11 Jan 25 '18 at 06:05
  • If you want to be not dependent on user manually tinkering with device time you can also have a look on device `boot time` – Kamil.S Mar 20 '18 at 11:38

1 Answers1

2

Apple definitely won't reject that. It's not in the Review Guidelines. I even have an app that uses TrueTime on the app store.

Regarding reliability, if you mean reliability by "how reliable it is to get correct true time", then it's quite reliable. It seems like that the library gets the time from time.apple.com. That seems to be from Apple, so I would say you can rely on it.

If you mean reliability by "how reliable it is to make successful requests" then that depends a lot: the user's Internet connection, bugs in the TrueTime library etc. According to the README,

  • Reachability events are automatically accounted for to pause/start requests.

  • UDP requests are executed in parallel, with a default limit of 5 parallel calls. If one fails, we'll retry up to 3 times by default.

So that's how the requests will behave.

Sweeper
  • 213,210
  • 22
  • 193
  • 313
  • Thanks for the explanation. I want to know reliable as is it for long term project. Let's say today I am using iOS 9 with swift 4 so after a year a new iOS version is released with new version of swift will it be reliable then ? – TechChain Jan 25 '18 at 08:56
  • @DhirajKumar It is unlikely that a new iOS version will break the pod. Swift version is irrelevant, since your code has already been compiled. If you are worried that the pod's author will not update the pod to newer Swift versions, my guess is that they will, but not necessarily. – Sweeper Jan 26 '18 at 06:37
  • Is there any alternate for this library ? – TechChain Mar 15 '18 at 10:32
  • @Techiee You can try NTPKit: https://github.com/ncvitak/NTPKit, written in Obj-C, so it bridges to Swift automatically and it won't break when new versions of swift comes out. – Sweeper Mar 16 '18 at 18:38
  • Does keep the offset between my device & server time ? – TechChain Mar 17 '18 at 09:21
  • What do you mean by "offset"? @Techiee You can always ask questions about a pod by posting an issue on the GitHub repo. – Sweeper Mar 17 '18 at 09:24
  • I check-out but I do not see It is taking time from time.apple.com. – TechChain Mar 17 '18 at 09:25
  • @Techiee You can use a custom server, like it showed in the README. – Sweeper Mar 17 '18 at 09:34
  • I can't use any custom server. What will be the default server here – TechChain Mar 17 '18 at 09:38
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/167015/discussion-between-sweeper-and-techiee). – Sweeper Mar 17 '18 at 09:39