0

I try to write c++ framework for ios app, and want distinguish iphone6 and iphone4, which have different cpu performance. I should close some modules only for iphone4. So is there a way to achieve it? Thanks.

This only about object-c solution, But I want ask if there is any api for c codes.

Community
  • 1
  • 1
LaiChen
  • 1
  • 2
  • 1
    Since you can call Objective-C methods from C or C++ code, it's hard to think of a reason why the Objective-C solution wouldn't be viable in the situation you describe. – Caleb Jul 06 '15 at 02:56

1 Answers1

0

The following could be used to get a C string representing the model of an iOS device

size_t size;  
sysctlbyname("hw.machine", NULL, &size, NULL, 0);  
char *machine = malloc(size);  
sysctlbyname("hw.machine", machine, &size, NULL, 0);  

This solution is taken from this Objective-C based answer, which also includes a list of what will be stored in machine. A list of these values can also be found on The iPhone Wiki.

The value for the iPhone 4 is iPhone3,x, with x being either 1, 2, or 3, depending on the specific model. The value for the iPhone 6 is iPhone7,x, with x being either 1 or 2.

Community
  • 1
  • 1
Chris Loonam
  • 5,735
  • 6
  • 41
  • 63