4

I am new to programming. As one of my app need updates if the device is shutting down (switched off), hence I need the current time when the device is getting switched off.

and I know that, we can get the system boot time (switched on time) with [NSProcessInfo processInfo].systemUptime .

but I need switched off time. Is there any way to get it! If yes please let me know how...? Edit: If No, Please let me know the reason...!

I also referred the below link. and it gives the system boot time (switched on time) only. Getting iOS system uptime, that doesn't pause when asleep

Please give me right solution if it is there...!

Community
  • 1
  • 1
Abirami Bala
  • 760
  • 1
  • 10
  • 25
  • In my knowledge is not possible, but your question is good – Anbu.Karthik Aug 17 '16 at 09:48
  • Possible duplicate of [Getting iOS system uptime, that doesn't pause when asleep](http://stackoverflow.com/questions/12488481/getting-ios-system-uptime-that-doesnt-pause-when-asleep) – PREMKUMAR Aug 17 '16 at 10:13
  • @Anbu karthik Thank you..! Anyway let us search if is there any possibilities... – Abirami Bala Aug 17 '16 at 10:13
  • good, really appreciate – Anbu.Karthik Aug 17 '16 at 10:16
  • @premkumar I also referred that link, and it gives the system boot time (switched on time) only. but i need it when the device is shutting down (switched off) – Abirami Bala Aug 17 '16 at 10:27
  • 1
    Having something store the system time at shutdown should be possible? If not, then getting the approximate time by having some kind of background service, which stores timestamp, after checking current uptime, to know if device was booted since last time timestamp was stored. So this question should be perfectly answerable. – hyde Sep 01 '16 at 16:12
  • 1
    @hyde Yes exactly, Now i got it. check my answer on : http://stackoverflow.com/questions/39118377/handle-app-while-the-device-getting-switched-off/39118643#39118643 – Abirami Bala Sep 02 '16 at 09:56

2 Answers2

0

Touch a file at shutdown. % touch mytimeToreboot

-1

You can't get Shut down time. you can get only ReBoot Time.

Apple is providing Following details only.

#define KERN_OSTYPE      1  /* string: system version */
#define KERN_OSRELEASE       2  /* string: system release */
#define KERN_OSREV       3  /* int: system revision */
#define KERN_VERSION         4  /* string: compile time info */
#define KERN_MAXVNODES       5  /* int: max vnodes */
#define KERN_MAXPROC         6  /* int: max processes */
#define KERN_MAXFILES        7  /* int: max open files */
#define KERN_ARGMAX      8  /* int: max arguments to exec */
#define KERN_SECURELVL       9  /* int: system security level */
#define KERN_HOSTNAME       10  /* string: hostname */
#define KERN_HOSTID     11  /* int: host identifier */
#define KERN_CLOCKRATE      12  /* struct: struct clockrate */
#define KERN_VNODE      13  /* struct: vnode structures */
#define KERN_PROC       14  /* struct: process entries */
#define KERN_FILE       15  /* struct: file entries */
#define KERN_PROF       16  /* node: kernel profiling info */
#define KERN_POSIX1     17  /* int: POSIX.1 version */
#define KERN_NGROUPS        18  /* int: # of supplemental group ids */
#define KERN_JOB_CONTROL    19  /* int: is job control available */
#define KERN_SAVED_IDS      20  /* int: saved set-user/group-ID */
#define KERN_BOOTTIME       21  /* struct: time kernel was booted */
#define KERN_NISDOMAINNAME  22  /* string: YP domain name */
#define KERN_DOMAINNAME     KERN_NISDOMAINNAME
#define KERN_MAXPARTITIONS  23  /* int: number of partitions/disk */
#define KERN_KDEBUG         24  /* int: kernel trace points */
#define KERN_UPDATEINTERVAL 25  /* int: update process sleep time */
#define KERN_OSRELDATE      26  /* int: OS release date */
#define KERN_NTP_PLL        27  /* node: NTP PLL control */
#define KERN_BOOTFILE       28  /* string: name of booted kernel */
#define KERN_MAXFILESPERPROC    29  /* int: max open files per proc */
#define KERN_MAXPROCPERUID  30  /* int: max processes per uid */
#define KERN_DUMPDEV        31  /* dev_t: device to dump on */
#define KERN_IPC        32  /* node: anything related to IPC */
#define KERN_DUMMY      33  /* unused */
#define KERN_PS_STRINGS 34  /* int: address of PS_STRINGS */
#define KERN_USRSTACK32 35  /* int: address of USRSTACK */
#define KERN_LOGSIGEXIT 36  /* int: do we log sigexit procs? */
#define KERN_SYMFILE        37  /* string: kernel symbol filename */
#define KERN_PROCARGS       38
                             /* 39 was KERN_PCSAMPLES... now deprecated */
#define KERN_NETBOOT        40  /* int: are we netbooted? 1=yes,0=no */
                             /* 41 was KERN_PANICINFO : panic UI information (deprecated) */
#define KERN_SYSV       42  /* node: System V IPC information */
#define KERN_AFFINITY       43  /* xxx */
#define KERN_TRANSLATE      44  /* xxx */
#define KERN_CLASSIC        KERN_TRANSLATE  /* XXX backwards compat */
#define KERN_EXEC       45  /* xxx */
#define KERN_CLASSICHANDLER KERN_EXEC /* XXX backwards compatibility */
#define KERN_AIOMAX     46  /* int: max aio requests */
#define KERN_AIOPROCMAX     47  /* int: max aio requests per process */
#define KERN_AIOTHREADS     48  /* int: max aio worker threads */
#ifdef __APPLE_API_UNSTABLE
#define KERN_PROCARGS2      49
#endif /* __APPLE_API_UNSTABLE */
#define KERN_COREFILE       50  /* string: corefile format string */
#define KERN_COREDUMP       51  /* int: whether to coredump at all */
#define KERN_SUGID_COREDUMP 52  /* int: whether to dump SUGID cores */
#define KERN_PROCDELAYTERM  53  /* int: set/reset current proc for delayed termination during shutdown */
#define KERN_SHREG_PRIVATIZABLE 54  /* int: can shared regions be privatized ? */
                             /* 55 was KERN_PROC_LOW_PRI_IO... now deprecated */
#define KERN_LOW_PRI_WINDOW 56  /* int: set/reset throttle window - milliseconds */
#define KERN_LOW_PRI_DELAY  57  /* int: set/reset throttle delay - milliseconds */
#define KERN_POSIX      58  /* node: posix tunables */
#define KERN_USRSTACK64     59  /* LP64 user stack query */
#define KERN_NX_PROTECTION  60  /* int: whether no-execute protection is enabled */
#define KERN_TFP        61  /* Task for pid settings */
#define KERN_PROCNAME       62  /* setup process program  name(2*MAXCOMLEN) */
#define KERN_THALTSTACK     63  /* for compat with older x86 and does nothing */
#define KERN_SPECULATIVE_READS  64  /* int: whether speculative reads are disabled */
#define KERN_OSVERSION      65  /* for build number i.e. 9A127 */
#define KERN_SAFEBOOT       66  /* are we booted safe? */
            /*  67 was KERN_LCTX (login context) */
#define KERN_RAGEVNODE      68
#define KERN_TTY        69  /* node: tty settings */
#define KERN_CHECKOPENEVT       70      /* spi: check the VOPENEVT flag on vnodes at open time */
#define KERN_THREADNAME     71  /* set/get thread name */
#define KERN_MAXID      72  /* number of valid kern ids */
/*
 * Don't add any more sysctls like this.  Instead, use the SYSCTL_*() macros
 * and OID_AUTO. This will have the added benefit of not having to recompile
 * sysctl(8) to pick up your changes.
 */
PREMKUMAR
  • 8,283
  • 8
  • 28
  • 51