如何确定模拟器中正在运行的设备? [英] How to determine the device running in the simulator?

查看:97
本文介绍了如何确定模拟器中正在运行的设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经查看了所有可用于确定应用程序正在运行的设备的代码,但是您怎么知道模拟器中正在运行的设备呢?

I've looked at all the code available for determining the device that an app is running on, but how can you tell what device is running in the simulator?

我以前从未遇到过此问题,因为我一直有可以测试的硬件.现在,iPhone 6/6 +已经发布,我只有6+,但是需要在模拟器中对6进行测试.当我使用此线程确定我使用的设备时正在运行,我得到的只是模拟器.

I've never had this issue before because I've always had hardware to test with. Now that the iPhone 6/6+ is out, I only have the 6+, but need to test on the 6 in the simulator. When I use this thread to determine what device I'm running on, all I get is the simulator.

谢谢.

推荐答案

尽管其他注释也很重要,但您实际上并不需要知道运行的设备是什么,您有可用的功能.即使这样,如果您只想输出此消息,则显示iPhone 6而不是Simulator也是错误的.只需添加适用于iPhone 6型号的正确代码即可,它应该可以正常工作,在这里并不会出错.

Although other comments have a point, you do not really need to know what device you are running on, what you do need to know is, what functionalities do you have available. And even so, if you just want to output this message, it would be wrong to display iPhone 6 instead of Simulator. Just add the correct code for the iPhone 6 model and it should work, not really much that can go wrong here.

但是,如果您仍然希望支持此操作,我会检查每个设备的硬编码分辨率.由于以编程方式,6+和6之间没有区别,除了分辨率,您可以使用它.但是请注意,模拟器实际上可以是您选择的任何大小,因此您必须对此有一个后备逻辑.

But if you still want to support this, I would go with checking hardcoded resolutions for each device. Since programatically there is no difference between 6+ and 6, except for resolution you could use this. But know that Simulator can be virtually any size you pick, so you must have a fallback logic for this.

因此分辨率为(以逻辑点为单位):

So the resolutions are (in logic points):

  • 320 x 480-iPhone 4/4S
  • 320 x 568-iPhone 5/5C/5S
  • 375 x 667-iPhone 6
  • 414 x 736-iPhone 6 +

由此您已经可以看到分辨率确实不是最好的方法,因为您看不到iPhone 5手机和iPhone 4之间的区别.您可以添加其他检查来解决此问题,您可以分开通过检查Touch ID是否可用或相似的方式来检查iPhone 5S.但是您将无法完全解决问题.

这篇关于如何确定模拟器中正在运行的设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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