+ (NSString*)deviceModel
{
NSString* machine = nil;
#if TARGET_IPHONE_SIMULATOR
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
machine = @"iPhone4,1";
else machine = @"iPad3,1";
#else
/* set 'oldp' parameter to NULL to get the size of the data
* returned so we can allocate appropriate amount of space
*/
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
if (!size) return nil;
// allocate the space to store name
char* name = malloc(size);
if (name)
{
// get the platform name
sysctlbyname("hw.machine", name, &size, NULL, 0);
// place name into a string
machine = [NSString stringWithUTF8String:name];
// exit it
free(name);
}
#endif
// ok?
return machine;
}
sysctlbyname
网友评论