How to detect iOS device programmatically

流过昼夜 提交于 2019-11-27 08:08:27

问题


I need to know which iOS device is currently running app (saying more exactly I need to know is device armv6 or armv7). UIUserInterfaceIdiomPad() could not check is device an iPhone4S or iPhone3G. Is it possible?


回答1:


Download https://github.com/erica/uidevice-extension (UIDevice-Hardware class) and you can use these:

[UIDevice currentDevice] platformType]   // returns UIDevice4GiPhone
[[UIDevice currentDevice] platformString] // returns @"iPhone 4G"

Or check if its retina

+ (BOOL) isRetina
{
    if([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
        return [[UIScreen mainScreen] scale] == 2.0 ? YES : NO;

    return NO;
}

Or check iOs version

+ (BOOL) isIOS5
{
    NSString *os5 = @"5.0";
    NSString *currSysVer = [[UIDevice currentDevice] systemVersion];

    //    currSysVer = @"5.0.1";
    if ([currSysVer compare:os5 options:NSNumericSearch] == NSOrderedAscending) //lower than 4
    {
        return NO;
    }
    else if ([currSysVer compare:os5 options:NSNumericSearch] == NSOrderedDescending) //5.0.1 and above
    {        
        return YES;
    }
    else // IOS 5
    {
        return YES;
    }

    return NO;
}



回答2:


If you really want to know (at run time) if you are running on arm6 or arm7, you can use "NXGetArchInfoFromCPUType" (much more detail is available in the accepted answer to this question).

Otherwise you can use platformType or platformString, as our incredibly quick answering friend Omar suggested (and +1 to him!).



来源:https://stackoverflow.com/questions/11081904/how-to-detect-ios-device-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!