Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I detect which iOS device my user is using?

I'm searching for a way to detect the device my app is running on. I am not interested in software version. I searched many questions but none of them (surprisingly) satisfy my needs for following reasons:

Solution 1:

NSString *deviceType = [UIDevice currentDevice].model;

This does not work because it gives me just "iPad". I want to know whether it is iPad, iPad 2, new iPad, iPhone 3GS, iPhone4 etc.

Solution 2: Not testing for device type, checking for individual capabilities

This does not apply because I want this data to collect user statistics, not to perform any device specific operation.

Solution 3: Using UIDeviceHardware found here

This code looks pretty outdated and seems to access private data on the device. There is even debate whether an app using this will get approved or not. More importantly, I have no idea how it works :) An alternative is also found here

Are any of the last two I mentioned safe to use? Are they future compliant? Do they comply with Apple approval rules?

Or is there any other method to get around this?

Thanks in advance.

like image 250
Murat Ögat Avatar asked Sep 01 '12 02:09

Murat Ögat


2 Answers

Apple uses such an API in it's sample code. To Quote the LargeImageDownsizing example project, in the file LargeImageDownsizingViewController.m beginning with line 83:

Choosing appropriate resulting image size and tile size can be done, but is left as an exercise to the developer. Note that the device type/version string (e.g. "iPhone2,1" can be determined at runtime through use of the sysctlbyname function:

size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString* _platform = [NSString stringWithCString:machine encoding:NSASCIIStringEncoding];
free(machine);

_platform in my case would be iPod4,1 for an iPod touch 4th gen.

This code is what is at the root of both of the Github examples you posted.

like image 142
NJones Avatar answered Sep 17 '22 15:09

NJones


Technically, [UIDeviceHardware platform] should work fine and you should send it to your server as it is. You should also send the iOS version along with the platform id to save you from trouble if the platform id would change in the future OS.

Because the function sysctlbyname being used here is well-documented, so I don't think Apple can use the rule number 2.5 against you. However, there still the rule number 17.1:

17.1 Apps cannot transmit data about a user without obtaining the user's prior permission and providing the user with access to information about how and where the data will be used

It is arguable if the device platform is about a user or not. My advice is that you should submit the app assuming you are not violating 17.1 and never ever mention about that. It is highly likely that the reviewer will not know what you are doing behind the scene.

like image 24
tia Avatar answered Sep 19 '22 15:09

tia