获取目标c中的启动时间 [英] Get the boot time in objective c
本文介绍了获取目标c中的启动时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在目标c中获得ios的启动时间?
how can i get the boot time of ios in objective c ?
有没有办法获得它?
推荐答案
不知道这是否适用于iOS,但在OS X(基本上是相同的操作系统)中,您将使用 sysctl()。这就是OS X Unix实用程序正常运行时间
的功能。 源代码可用 - 搜索启动时间 。
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];
}
iOS沙盒环境中编程的限制性可能会使其无效,我不知道,我还没试过。
The restricted nature of programming in the iOS sandboxed environment might make it not work, I don't know, I haven't tried it.
这篇关于获取目标c中的启动时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文