How to detect iOS device programmatically

后端 未结 2 1641
孤街浪徒
孤街浪徒 2020-12-11 23:16

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 a

2条回答
  •  长情又很酷
    2020-12-11 23:45

    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;
    }
    

提交回复
热议问题