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

北城以北 提交于 2019-12-01 03:59:02

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.

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.

The UIDeviceHardware you mentioned is good enough but a bit outdated. You can try out this Made it more apple-style, so may by they will like it more.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!