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

2020-03-07 07:20发布

I need to get the iPhone model number from code. I can see the model number from my iPhone which is "MC143C", but when I am retrieving this by using code it is returning "iPhone". This is the code I am using to get the model number.

NSLog(@"model: %@", [[UIDevice currentDevice] model]);

Can anyone please help me to have the information i want to get from my device.

Thanks, !ZAQ

3条回答
ゆ 、 Hurt°
2楼-- · 2020-03-07 07:28

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.

查看更多
▲ chillily
3楼-- · 2020-03-07 07:33

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;   
}
查看更多
在下西门庆
4楼-- · 2020-03-07 07:50

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.

查看更多
登录 后发表回答