gpt4 book ai didi

objective-c - NSDate:获取独立于设备时钟的精确时间?

转载 作者:可可西里 更新时间:2023-11-01 03:06:02 28 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
How can I locally detect iPhone clock advancement by a user between app runs?
Is there a way to determine the actual time and date in iOS (not the time of the device)
Is there a clock in iOS that can be used that cannot be changed by the user

简介

我正在使用一个基于订阅的自动续订应用程序。当应用程序收到来自 Apple 的最新收据时,它会将 expires_date_ms 键存储在 NSUserDefaults 中。 30 天后,该应用会与 Apple 核实订阅是否仍然有效。该应用程序可以被视为离线应用程序,但它必须每 30 天连接一次互联网才能检查订阅状态。此时间比较将用于告诉用户他/她必须连接。

问题

我正在使用下面的代码将当前时间与 expires_date_ms 进行比较:

NSTimeInterval expDateMS = [[productInfo objectForKey:@"expires_date_ms"] doubleValue];
NSTimeInterval currentDateMS = ([[NSDate date] timeIntervalSince1970] * 1000);

if (currentDateMS > expDateMS)
subExpired = YES;

这很好并且运行良好,但据我所知,存在一个可以被利用的漏洞 - 如果用户将设备的时钟设置为一小时/月/十年,时间比较将变得不可靠,因为 [ NSDate date] 使用设备的当前时间(如有错误请指正)。

问题

有没有办法以毫秒为单位检索与设备无关的时间?一种可以在不考虑设备时钟的情况下准确可靠地测量的方法?

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com