Detecting processor cores on an iOS device

I write code with dispatch_async and get different results on iphone 4s and ipad 1st gen.

I am wondering if this is due to the number of cores that the processor has. Is it possible to determine the number of cores or processor type of an iOS device at runtime so that I can dispatch_async on 4s but not on ipad?

+4
source share
1 answer

Here is the code to determine the number of cores on an iOS device:

 #include <sys/sysctl.h> unsigned int countCores() { size_t len; unsigned int ncpu; len = sizeof(ncpu); sysctlbyname ("hw.ncpu",&ncpu,&len,NULL,0); return ncpu; } 

In addition, you can select the [[UIDevice currentDevice] userInterfaceIdiom] check box to determine if the device is an iPhone or iPad. Like this:

 if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { NSLog(@"iPad"); } else { NSLog(@"iPhone"); } 

Link

+7
source

Source: https://habr.com/ru/post/1439143/


All Articles