I am writing some code with dispatch_async
and get different results on an iphone 4s and ipad 1st gen.
I am wondering if it is due to the number of cores the CPU has. Is it possible to detect the number of cores or CPU type of an iOS device at runtime so I can dispatch_async
on the 4s, but not on the ipad?
Here's the code to detect 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 to that, you can check against the [[UIDevice currentDevice] userInterfaceIdiom]
to determine if the device is an iPhone or an iPad. Like this:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
NSLog(@"iPad");
}
else {
NSLog(@"iPhone");
}
Reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With