如何在 Swift 5 中验证用户的时间是否真实并且没有欺骗应用程序?

How to verify that a user's time is true and is not spoofing an app in Swift 5?

我想验证应用程序用户是否没有乱用时间设置来欺骗我的交易应用程序上的交易时间。我正在使用 Firestore 作为我的数据库。最明智的做法是什么?

确保您可以信任时间戳的最简单方法是 use Firestore's built in server timestamp。来自文档:

db.collection("objects").document("some-id").updateData([
    "lastUpdated": FieldValue.serverTimestamp(),
])

如果不能使用服务器时间戳,可以使用Firestore的服务器端安全规则,至少保证客户端传递的时间戳在合理范围内。为此,将内置 request.time variable 与客户端指定的值进行比较。