I have the following code in my iPhone app which returns the model type
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *modelType = malloc(size);
sysctlbyname("hw.machine", modelType, &size, NULL, 0);
NSString *deviceModel = [NSString stringWithCString:modelType encoding:NSUTF8StringEncoding];
free(modelType);
but on some user's devices I get nil. The devices that return nil have Location Services.
1) What could cause nil to be returned?
2) Is nil returned on jail broken devices?
3) Is there a better way to check for model type on iDevices?
Try this instead:
#import <sys/utsname.h>
- (NSString *)machine {
struct utsname si;
uname(&si);
NSString *res = [NSString stringWithCString:si.machine encoding:NSUTF8StringEncoding];
return res;
}
I actually added this as a category method on UIDevice
.
This gives the various "iPhone4,1", "iPad2,4" type values.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.