NSTimeInterval
システムの再起動後の取得に問題があります。この関数は間違った結果をもたらしました。デバイスのバッテリーが充電されると、再起動時間が再開されます。iPhone 5s と iPad 3 (新品) に不具合があります。どうすれば修正できますか?
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 に答える