How to get the model of iPhone from code. (e.g. MC143C)

北城以北 提交于 2019-12-01 01:46:33
Vanguarder

import https://github.com/erica/uidevice-extension

1. define modelnumber in UIDevice-IOKitExtensions.h

- (NSString *) modelnumber; 

2. add the following code to UIDevice-IOKitExtensions.m

- (NSString *) modelnumber{
    NSArray *results = getValue(@"model-number");
    if (results){
        NSString *mn=[[results objectAtIndex:0] copy];
        return  mn;
    }
    return nil;   
}

As usual, if some info cannot be found in the doc, it uses a private API.

In this case, Preferences.app uses IAP.framework to get the info.

I'm not sure the exact use case you have, but take a look at this: http://github.com/ars/uidevice-extension

It gets you pretty much all the relevant information. Not the exact model number, but you can get the base model (iPhone 3G) and all its capabilities as an ORed value of enumerations.

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