如何检测用户使用的iOS设备? [英] How do I detect which iOS device my user is using?

查看:230
本文介绍了如何检测用户使用的iOS设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来检测我的应用运行的设备。我对软件版本不感兴趣。我搜索了很多问题但其中没有一个(令人惊讶地)满足了我的需求,原因如下:

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:

解决方案1:

NSString *deviceType = [UIDevice currentDevice].model;

这不起作用,因为它只给我iPad。我想知道它是iPad,iPad 2,新iPad,iPhone 3GS,iPhone4等。

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.

解决方案2:不测试设备类型,检查个别功能

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.

解决方案3:使用UIDeviceHardware 此处

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

我提到的最后两个中的任何一个都可以安全使用吗?他们未来是否合规?他们是否遵守Apple批准规则?

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?

提前致谢。

推荐答案

Apple使用这样的API这是示例代码。引用 LargeImageDownsizing 示例项目,在第83行开头的文件 LargeImageDownsizingViewController.m 中:

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:


可以选择合适的结果图像大小和图块大小,
但是留给开发人员练习。请注意,设备
类型/版本字符串(例如iPhone2,1可以通过使用sysctlbyname函数在运行时确定

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在我的情况下将是 iPod4,1 用于iPod touch第4代。

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

此代码是您发布的两个Github示例的根源。

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

这篇关于如何检测用户使用的iOS设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆