想知道是否可以检查设备(iPhone,iPad,iPod,即iOS设备)是否有陀螺仪?如何检查设备上是否有陀螺仪?
6
A
回答
13
- (BOOL) isGyroscopeAvailable
{
#ifdef __IPHONE_4_0
CMMotionManager *motionManager = [[CMMotionManager alloc] init];
BOOL gyroAvailable = motionManager.gyroAvailable;
[motionManager release];
return gyroAvailable;
#else
return NO;
#endif
}
也看到我这篇博客就知道,你可以在iOS设备 http://www.makebetterthings.com/blogs/iphone/check-ios-device-capabilities/
3
CoreMotion的运动经理类内置了用于检查硬件可用性属性检查不同的能力。 Saurabh的方法会要求您在每次发布带有陀螺仪的新设备(iPad 2等)时更新您的应用程序。下面是使用苹果的记录属性检查陀螺仪可用性的示例代码:
CMMotionManager *motionManager = [[[CMMotionManager alloc] init] autorelease];
if (motionManager.gyroAvailable)
{
motionManager.deviceMotionUpdateInterval = 1.0/60.0;
[motionManager startDeviceMotionUpdates];
}
更多信息,请参见the documentation。
1
我相信@Saurabh和@Andrew Theis的答案只是部分正确的。
这是一个更完整的解决方案:
- (BOOL) isGyroscopeAvailable
{
// If the iOS Deployment Target is greater than 4.0, then you
// can access the gyroAvailable property of CMMotionManager
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0
CMMotionManager *motionManager = [[CMMotionManager alloc] init];
BOOL gyroAvailable = motionManager.gyroAvailable;
[motionManager release];
return gyroAvailable;
// Otherwise, if you are supporting iOS versions < 4.0, you must check the
// the device's iOS version number before accessing gyroAvailable
#else
// Gyro wasn't available on any devices with iOS < 4.0
if (SYSTEM_VERSION_LESS_THAN(@"4.0"))
return NO;
else
{
CMMotionManager *motionManager = [[CMMotionManager alloc] init];
BOOL gyroAvailable = motionManager.gyroAvailable;
[motionManager release];
return gyroAvailable;
}
#endif
}
凡SYSTEM_VERSION_LESS_THAN()
在this StackOverflow answer定义。
+0
I通过查看这个页面上的所有答案,我完全感到困惑。 @jonsibley“gyroAvailable”方法只适用于IOS4 +吗? – ShayanK 2012-04-23 11:32:07
相关问题
- 1. 如何在无陀螺仪的设备上创建CMRotationMatrix
- 2. 没有陀螺仪的VR
- 3. iPhone 4没有陀螺仪?
- 4. iPhone/iPad陀螺仪
- 5. iOS陀螺仪API
- 6. 使用陀螺仪来检测物体是否直线
- 7. 如何在Android中使用陀螺仪
- 8. iOS - 陀螺仪样本
- 9. Android陀螺仪示例?
- 10. CMMotionManager和iPhone 4上的陀螺仪
- 11. 哪些Android手机有陀螺仪?
- 12. 陀螺仪不显示任何漂移
- 13. 如何在Game Maker Studio上实现Android陀螺仪?
- 14. 陀螺仪更新核心运动
- 15. Android陀螺仪Y轴滚轴
- 16. 陀螺仪vs加速度计?
- 17. 基于磁力计和陀螺仪
- 18. iOS-开始接收陀螺仪更新
- 19. 陀螺仪更新无法启动
- 20. 在Unity3d中使用Android陀螺仪
- 21. 用陀螺仪导航视图 - iOS
- 22. 从陀螺仪获得角度
- 23. iPhone倾斜角度 - 使用陀螺仪?
- 24. 加速度计和陀螺仪数据
- 25. 陀螺仪传感器的结果Android
- 26. gluLookAt从陀螺仪角度向量
- 27. IOS加速度计/陀螺仪问题
- 28. 在陀螺仪和手指滑动模式之间是否有组件切换?
- 29. iPhone - 用陀螺仪/加速度计检测运动
- 30. 陀螺仪的直线运动可以被检测到吗?
使用#ifdef有什么优势? – jonsibley 2012-01-07 22:35:31
@jonsibley CMMotionManager仅适用于iPhone OS 4 ..如果我们尝试在早期的操作系统上使用它,它将无法编译 – Saurabh 2012-01-08 09:25:52
明白了,谢谢。 – jonsibley 2012-03-24 13:10:28