Identify iPhone models

Previous topic - Next topic

mrplant

I would like to be able to identify iphone /iPad models but reckon objective c would need to be required to do this .
I'm sure I saw one on this forum before unless I am thinking of ones I have seen elsewhere in pure objective c.

Anyone written such a function already ?

Thanks

spacefractal

#1
Look on the xCode 6 project im gave in the eailer thread. The code is in the file UIDeviceHardware.m (there is two other functions, not shown here, but is irrevent here).

Code (glbasic) Select

//
//  UIDeviceHardware.m
//
//  Used to determine EXACT version of device software is running on.

#include <sys/types.h>
#include <sys/sysctl.h>
#import <Foundation/NSString.h>
#import <string.h>
#import <stdlib.h>
char iDevice[256]="";

const char* deviceName()
{ int name[] = {CTL_HW,HW_MACHINE};
size_t size = 100;
sysctl(name, 2, NULL, &size, NULL, 0); // getting size of answer
char *hw_machine = malloc(size);
sysctl(name, 2, hw_machine, &size, NULL, 0);
NSString *hardware = [NSString stringWithUTF8String:hw_machine];
strcpy(iDevice, [hardware UTF8String]);
free(hw_machine);

return iDevice;
}


here from glbasic:
IMPORT "C" const char* deviceName()
LOCAL devicefull$ = deviceName()

Here is the string its returns:
http://stackoverflow.com/questions/19584208/identify-new-iphone-model-on-xcode-5-5c-5s


[/code]
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

mrplant

Aha thanks space fractal.
I'll try that out and write a function for identifiing the models .

Have now found your earlier forum post on it.

Thanks again.

mrplant

Hi I am having problems with Xcode compiling that routine - it kept complaining about the syntax etc.

I just noticed I am putting it into a .mm file and it is a .m file.

Would it take much to make it compatible in .mm format which I think if memory serves me is an objective-c file, whilst .m is pure C correct?

snippet of what I am adding to current .mm file below..

wouldn't I just need to add extern "C" and a few other things? Sorry I tried this but my objective-c isn't that great when it comes to figuring things out..

anyone?

extern "C" void iOSEnableAutoLock(int value) {

// Enable iOS AutoLock function. The setting of NO then YES is a hack to ensure it works everytime, not a mistake!

if (value) {
[UIApplication sharedApplication].idleTimerDisabled = NO;
} else  {
[UIApplication sharedApplication].idleTimerDisabled = NO;
[UIApplication sharedApplication].idleTimerDisabled = YES;
}
}

char iDevice[256]="";

const char* deviceName() {
   

   
    // Under test.
   
int name[] = {CTL_HW,HW_MACHINE};

size_t size = 100;
sysctl(name, 2, NULL, &size, NULL, 0); // getting size of answer
char *hw_machine = malloc(size);
sysctl(name, 2, hw_machine, &size, NULL, 0);
NSString *hardware = [NSString stringWithUTF8String:hw_machine];
strcpy(iDevice, [hardware UTF8String]);
free(hw_machine);
   
return iDevice;

}
   

spacefractal

#4
you cant mix objective-c and c code to the same file, but you can uses both mm and m files to the same project. So split iOSEnableAutoLock into own mm file, and then leave UIDeviceHardware.m as its are.

PS. im are no expert in those either, im are more experiered with Java.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

mrplant

Thanks for that info - I'll take your advice and use the two files exactly as you said.
Fingers crossed .

mrplant

Works great thanks.