How to programmatically differentiate between iphone 4 and iphone 4S?

后端 未结 7 1601
醉酒成梦
醉酒成梦 2020-11-29 18:08

I am working on app which needs to check the iphone model, but I\'m not able to find any solution. I will be thank full for any suggestion.

7条回答
  •  独厮守ぢ
    2020-11-29 18:52

    Here is a common method of retriving the device model. There are no NS methods for this, so you gotta use c

    #include 
    #include 
    
    - (NSString *)machine {
        NSString *machine;
        size_t size;
        sysctlbyname("hw.machine", NULL, &size, NULL, 0);
        char *name = malloc(size);
        sysctlbyname("hw.machine", name, &size, NULL, 0);
        machine = [NSString stringWithUTF8String:name];
        free(name);
        return machine;
    }
    

提交回复
热议问题