iOS how to detect user has changed system time, and if not compare device time with server time

前端 未结 4 1473
名媛妹妹
名媛妹妹 2021-01-01 01:22

The requirement is that have to detect if the system time of iPhone is changed by user manually. For that I have used

NSNotificationCenter.defaultCenter         


        
4条回答
  •  猫巷女王i
    2021-01-01 02:09

    As per its documentation, NSSystemClockDidChangeNotification is:

    Posted whenever the system clock is changed. This can be initiated by a call to settimeofday() or the user changing values in the Date and Time Preference panel.

    So unless you were expecting the user to change the date or time while your app is running, you're obviously not going to hear anything. Notifications are triggered by events.

    iOS doesn't provide you with a way to ask on whose authority the system believes the time and date is the current value — whether it's carrier network time, time server time, user-supplied time or something else. There's no single server time and no way to ask for it. What you want to do cannot be done.

提交回复
热议问题