size_t size; // Set 'oldp' parameter to NULL to get the size of the data // returned so we can allocate appropriate amount of space sysctlbyname("hw.machine", NULL, &size, NULL, 0); // Allocate the space to store name char *name = malloc(size); // Get the platform name sysctlbyname("hw.machine", name, &size, NULL, 0); // Place name into a string NSString *machine = [NSString stringWithCString:name encoding:NSUnicodeStringEncoding]; // Done with this free(name); return machine;
but iOS App Programming Guide in fact got a more decent way to do this.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { // The device is an iPad running iOS 3.2 or later. } else { // The device is an iPhone or iPod touch. }
沒有留言:
發佈留言