-6

My requirement is to fetch purchase date of iOS device. Can it is possible through code.

jscs
  • 63,694
  • 13
  • 151
  • 195
Rajeev Singh
  • 198
  • 1
  • 11

1 Answers1

0

Short answer: no. Best you can get is information on when the device was turned on

#include <sys/sysctl.h>

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;
}

NSDate *bootDate = [NSDate dateWithTimeIntervalSinceNow:((NSTimeInterval)-uptime)]
mag_zbc
  • 6,801
  • 14
  • 40
  • 62
  • Keep in mind that this heavily relies on private APIs, so Apple *will* reject your app from the App Store if you have this functionality in it. – Tamás Sengel Aug 04 '17 at 11:27
  • [Not necessarily](https://stackoverflow.com/questions/32140756/does-apple-allow-the-usage-of-sysctl-h-within-ios-applications). Besides, if this api wasn't supposed to be used, it wouldn't be exposed. – mag_zbc Aug 04 '17 at 11:29
  • Private APIs are private for a reason. If you use a private API and get caught, your app will get rejected, since it against AppStore's rules. There are quire a few private APIs that developers have found, but being able to use something is not the same as being allowed to use it... – Dávid Pásztor Aug 04 '17 at 16:15