开发者

How to know the device?

开发者 https://www.devze.com 2023-03-13 13:42 出处:网络
I am developing a comic book using Cocoa Touch in Xcode.I dont know how to get the开发者_运维百科 details of the device whether the device is iphone, ipad or ipod.

I am developing a comic book using Cocoa Touch in Xcode.I dont know how to get the开发者_运维百科 details of the device whether the device is iphone, ipad or ipod.

I am trying for an universal build.

How to identify the device? Is there a way to change the screen size according to the device?


You can use this for you first question -

   + (BOOL)isDeviceAniPad {
    #ifdef UI_USER_INTERFACE_IDIOM
        return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
    #else
        return NO;
    #endif
    }

And for you second you don't need to change it your self the iphone/ipad will use use the views sizes that fits its screen. you will have to supply different images sizes or to scale them to the size of the screen.


Don't try to check for specific device models, instead check for features of a device.

For screen size lookup UIUserInterfaceIdiom in the docs.


NSString *deviceType = [UIDevice currentDevice].model;
NSLog(@"%@",deviceType);

       or


if you need to differentiate between all three types of devices:

Determine device (iPhone, iPod Touch) with iPhone SDK


UIDevice class:

NSString *deviceType = [UIDevice currentDevice].model;

if([deviceType isEqualToString:@"iPhone"])
    // it's an iPhone


size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0); 
char *name = malloc(size);
sysctlbyname("hw.machine", name, &size, NULL, 0);

now you can compare like
if (strcmp(name, "iPhone1,1")) and others ... "iPhone1,2" ...

0

精彩评论

暂无评论...
验证码 换一张
取 消