I need to know the current date to query CloudKit data with it, like:
let predicate = NSPredicate(format: "publishedAt <= %@", currentDateAndTime)
I don't need high precision, even +/- a few minutes is fine, but I can't rely on device's time since the user can manually change it.
Researching this myself I see that the most reliable method is to get the date from the server.
-
There are NTP servers, but accessing them requires additional libraries which adds complexity. TrueTime (last updated 6 years ago) and Kronos (updated like once a year) seem outdated, given how much Swift has changed in the past years.
-
I can make an HTTP request to a website like Google or Apple and read the current time from its headers. But I don't know if this method is reliable.
-
I know I can create a dummy record in CloudKit, update it, and read its modificationDate. But it feels hacky.
Maybe there is another way to fetch the current date directly from CloudKit?
It feels like it should be easy and there is a straightforward solution, but I just can't find it.