Hi!
I'm exploring options to prevent date tampering on my app. One of those options involves obtaining the uptime of the device using sys/sysctl.h which I understand is an approved and supported way to do for macOS but I'm not sure if it would be approved during an Apple Review for my iOS app.
Does anyone know or have experience with this? Is it ok or will it get my app rejected?
I leave my code as reference here:
#include <sys/types.h>
#include <sys/sysctl.h>
+ (time_t)uptime
{
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;
}
Thanks for any help you could provide
However, certain entries return
EPERM
to indicate that Apple has blocked them. I don’t know where those may be documented
My general advice here is that you stick to the selectors documented in the sysctl
man page (chapter 3). However, this is one of those places where I’m reluctant to promise long-term binary compatibility, even for selectors that are documented. The sysctl
design was inherited from iOS’s ancestor platforms (macOS and thence BSD) and it exposes a bunch of info that we wouldn’t expose if we were starting from scratch. You can find my favourite quote about this in the footnote on this post.
With regards kern.boottime
specifically, I understand the utility of that in achieving this goal:
I'm exploring options to prevent date tampering on my app.
My advice here is that, once you’ve come to a decision as to your expedient solution, file an enhancement request for some a better API, making sure to describe both your requirements and the steps you’re taking in the absence of such an API.
Please post your bug number, just for the record.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"