Skip to content

Commit

Permalink
Use another method for uptime on iOS and MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
AGulev committed Sep 25, 2021
1 parent 1363997 commit 3711770
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
9 changes: 0 additions & 9 deletions uptime/ext.manifest
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
name: "UpTime"

platforms:
arm64-ios:
context:
frameworks: ["AVFoundation"]

armv7-ios:
context:
frameworks: ["AVFoundation"]
17 changes: 15 additions & 2 deletions uptime/src/UpTime_ios.mm
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
#if defined(DM_PLATFORM_IOS) || defined(DM_PLATFORM_OSX)
#include <AVFoundation/AVFoundation.h>

#include <sys/sysctl.h>

uint32_t UpTime_get()
{
return [[NSProcessInfo processInfo] systemUptime];
struct timeval boottime;
int mib[2] = {CTL_KERN, KERN_BOOTTIME};
size_t size = sizeof(boottime);
time_t now;
time_t uptime = -1;

(void)time(&now);

if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 && boottime.tv_sec != 0) {
uptime = now - boottime.tv_sec;
return uptime;
}
return 0;
}

#endif

0 comments on commit 3711770

Please sign in to comment.