确定 iPhone 的硬件

发布于 2024-09-14 08:54:12 字数 181 浏览 0 评论 0原文

如何判断应用程序是在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陪你到最终 2024-09-21 08:54:12

您应该查找并使用 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 and gyroAvailable 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.

执手闯天涯 2024-09-21 08:54:12

RE:检测闪存是否可用的示例代码

   for (AVCaptureDevice *cameraDevice in [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]) {
        if ([cameraDevice hasFlash]) {
            NSLog(@" Yay! A flash!"):
        }
    }

但是说真的,伙计,弗拉基米尔给了你类名和方法名。如果您打开了文档,您很快就会弄清楚它 - 当然比等待别人向您粘贴五行代码要快。

RE: sample code to detect if a flash is available

   for (AVCaptureDevice *cameraDevice in [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]) {
        if ([cameraDevice hasFlash]) {
            NSLog(@" Yay! A flash!"):
        }
    }

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文