TrueTime.swift icon indicating copy to clipboard operation
TrueTime.swift copied to clipboard

Getting Reference Time into UserDefaults error

Open MohamedJaffer-24 opened this issue 5 years ago • 0 comments

switch result { case let .success(referenceTime): BatteryStatusHandler.refTime = referenceTime let ud = UserDefaults.standard ud.set(referenceTime, forKey: "NTPTime")

                case let .failure(error):
                        print("Error! \(error)")
        }

In the above code, I tried to set reference Time into User Defaults , But it is a non-property list in user defaults. How can i change this to NSData or NSString to set it in userDefaults

Error: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to insert non-property list object ReferenceTime(underlyingValue: FrozenNetworkTime(time: 2020-02-14 10:39:08 +0000, uptime: 611876232 ms, serverResponse: NTPResponse(packet: ntp_packet_t(client_mode: 4, version_number: 3, leap_indicator: 0, stratum: 1, poll: 3, precision: 235, root_delay: ntp_time32_t(whole: 0, fraction: 0), root_dispersion: ntp_time32_t(whole: 0, fraction: 11), reference_id: (83, 72, 77, 0), reference_time: 1581676744029 ms, originate_time: 1581680346866 ms, receive_time: 1581676748052 ms, transmit_time: 1581676748052 ms), responseTime: 1581680347149 ms, receiveTime: 1581680347149 ms), startTime: 1581680346866 ms, sampleSize: 20, host: 123.14.253.17:123) for key NTPTime' *** First throw call stack: (0x1acb8b180 0x1abd639f8 0x1aca953a0 0x1acbbcdc4 0x1acbbd46c 0x1acbbd1e0 0x1acbbd524 0x1aca7a3dc 0x1acb08c54 0x1acb08698 0x1aca76d64 0x1aca79d7c 0x1acbc7360 0x1ad5273b8 0x100eb7cf0 0x1016be098 0x1016be274 0x1016be30c 0x1016b7f7c 0x10176f6f4 0x101770c78 0x10177e6fc 0x1acb1cb20 0x1acb17a58 0x1acb16fb4 0x1aed1879c 0x1d9378c38 0x100f5871c 0x1ac5da8e0) libc++abi.dylib: terminating with uncaught exception of type NSException

MohamedJaffer-24 avatar Feb 14 '20 10:02 MohamedJaffer-24