3

目標 c で ios の起動時間を取得するにはどうすればよいですか?

それを取得する方法はありますか?

4

2 に答える 2

12

Don't know if this will work in iOS, but in OS X (which is essentially the same OS) you would use sysctl(). This is how the OS X Unix utility uptime does it. Source code is available - search for "boottime".

#include <sys/types.h>
#include <sys/sysctl.h>  

// ....  

#define MIB_SIZE 2  

int mib[MIB_SIZE];
size_t size;
struct timeval  boottime;

mib[0] = CTL_KERN;
mib[1] = KERN_BOOTTIME;
size = sizeof(boottime);
if (sysctl(mib, MIB_SIZE, &boottime, &size, NULL, 0) != -1)
{
    // successful call
    NSDate* bootDate = [NSDate dateWithTimeIntervalSince1970:boottime.tv_sec];
}

The restricted nature of programming in the iOS sandboxed environment might make it not work, I don't know, I haven't tried it.

于 2012-04-26T10:37:04.063 に答える