如何在 objective c 中获取 ios 的启动时间?
有办法得到吗?
最佳答案
不知道这是否适用于 iOS,但在 OS X(本质上是相同的操作系统)中您可以使用 sysctl() . OS X Unix 实用程序 uptime
就是这样做的。 Source code可用 - 搜索“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];
}
在 iOS 沙盒环境中编程的受限性可能使其无法工作,我不知道,我还没有尝试过。
关于objective-c - 在 objective-c 中获取启动时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10331020/