如果用户将他们的设备当前时间更改为过去时间并尝试离线登录尝试,如何检测?
我们必须找到设备的当前位置 UTC 时间。我们尝试了 Nodatime,xamarin .ios 的 CLLocationManager,反向 GeocodeCoder。它都提供设备时间而不是当前位置时间。
反向地理编码提供当前设备的位置时区。使用它,我们尝试使用 Nodatime 的 SystemClock.Instance.InZone(locationTimeZone).InUtc() 获取位置当前时间。 不幸的是,这也是设备当地时间。
至少,如果他将时间更改为过去的时间,我们会尝试通知用户。为此,我们在通知中心尝试了 SystemClockChanges。
NSNotificationCenter.DefaultCenter.AddObserver(new NSString("NSSystemClockDidChangeNotification"), SystemClockChanged); NSNotificationCenter.DefaultCenter.AddObserver(new NSString("NSSystemTimeZoneDidChangeNotification"), SystemClockTimeZoneChanged); NSNotificationCenter.DefaultCenter.AddObserver(new NSString("UIApplicationSignificantTimeChangeNotification"), SignificantTimeChanged);
如果他做了 1 小时/2 小时或最小时间更改,它也无法检测到。
我们期待设备的位置时间像 mono.android LocationManger 一样用于离线登录尝试