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

前端 未结 3 1175
梦谈多话
梦谈多话 2021-01-07 11:17

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 \

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-07 11:47

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

提交回复
热议问题