确定 iPhone 的硬件
如何判断应用程序是在 iPhone 4、iPhone 3GS 还是 iPad 上运行?
我想确定我正在使用哪种硬件,然后如果是 iPhone 4,则提供附加功能(例如使用视频灯或陀螺仪传感器)。
任何帮助将不胜感激。
谢谢
PS:我希望以编程方式确定这一点,而不是根据物理外观来确定。
How can I tell if the application is running on iPhone 4 or iPhone 3GS or an iPad?
I want to determine if which hardware I'm using and then provide additional functionality if it's an iPhone 4 (such as using the video light or gyro-sensor).
Any help would greatly be appreciated.
Thanks
PS: I'm looking to determine this programmatically and not determine if based on physical appearance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该查找并使用 API 检查所需的功能是否可用,而不是确定设备型号。例如,用于闪存的 AVCaptureDevice 的
hasFlash
属性和用于陀螺仪的 CMMotionManager 的gyroAvailable
属性。如果您的应用程序可以在 iOS4 之前的 iOS 上运行,您还应该执行额外检查上面列出的属性和类在运行时是否可用。
Rather then determining device model you should find and use APIs checking if desired functionality is available. For example
hasFlash
property of AVCaptureDevice for flash andgyroAvailable
property of CMMotionManager for gyroscope.If your app can run on iOS prior to iOS4 you should also perform extra check if listed above properties and classes are available in run-time.
RE:检测闪存是否可用的示例代码
但是说真的,伙计,弗拉基米尔给了你类名和方法名。如果您打开了文档,您很快就会弄清楚它 - 当然比等待别人向您粘贴五行代码要快。
RE: sample code to detect if a flash is available
But seriously, dude, Vladimir gave you the class name and the method name. If you had opened the documentation, you'd have had figured it out in a jiffy - certainly quicker than waiting on someone to paste you five lines of code.