0

Is this possible to get Last shutdown or reboot time using objective c or Swift.

I tried many websites and forums. i can't find solution for this problem.

PREMKUMAR
  • 8,283
  • 8
  • 28
  • 51
  • 1
    Have you checked http://stackoverflow.com/questions/12488481/getting-ios-system-uptime-that-doesnt-pause-when-asleep ? – fiks Jul 27 '16 at 10:17

2 Answers2

3

Check out NSProcessInfo there is a property called systemUptime of type NSTimeInterval

NSProcessInfo.processInfo().systemUptime
[[NSProcessInfo processInfo] systemUptime]

I gave you your answer in both objective-c and swift since you tagged them both.

Happiehappie
  • 1,084
  • 2
  • 13
  • 26
2

You cannot detect the last shutdown time. But you can detect the last reboot time as: let systemUptime = NSProcessInfo.processInfo().systemUptime;

And to detect the time, since last reboot is:

    let systemUptime = NSProcessInfo.processInfo().systemUptime;
    let timeNow = NSDate().timeIntervalSince1970
    let dateOfLastReboot = NSDate(timeIntervalSince1970: timeNow-systemUptime)
Ankit Thakur
  • 4,739
  • 1
  • 19
  • 35