NSTimeInterval
我在系统重启后遇到了麻烦。这个函数给了我一个错误的结果。当设备的电池充满电时,重启时间会重新开始。iPhone 5s 和 iPad 3(新)有问题。我该如何解决?
问问题
686 次
1 回答
0
我使用这种方法,它对我有帮助
public static func uptime() -> (days: Int, hrs: Int, mins: Int, secs: Int) {
var currentTime = time_t()
var bootTime = timeval()
var mib = [CTL_KERN, KERN_BOOTTIME]
// NOTE: Use strideof(), NOT sizeof() to account for data structure
// alignment (padding)
// http://stackoverflow.com/a/27640066
// https://devforums.apple.com/message/1086617#1086617
var size = strideof(timeval)
let result = sysctl(&mib, u_int(mib.count), &bootTime, &size, nil, 0)
if result != 0 {
#if DEBUG
print("ERROR - \(__FILE__):\(__FUNCTION__) - errno = "
+ "\(result)")
#endif
return (0, 0, 0, 0)
}
于 2016-01-09T09:53:20.537 回答