只是想知道我可以检查设备(iPhone、iPad、iPod 即 iOS 设备)是否有陀螺仪?
问问题
2973 次
3 回答
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/
于 2011-06-02T18:04:46.517 回答
3
CoreMotion 的运动管理器类具有用于检查硬件可用性的内置属性。Saurabh 的方法要求您在每次发布带有陀螺仪的新设备(iPad 2 等)时更新您的应用程序。这是使用 Apple 记录的属性来检查陀螺仪可用性的示例代码:
CMMotionManager *motionManager = [[[CMMotionManager alloc] init] autorelease];
if (motionManager.gyroAvailable)
{
motionManager.deviceMotionUpdateInterval = 1.0/60.0;
[motionManager startDeviceMotionUpdates];
}
有关更多信息,请参阅文档。
于 2011-06-17T20:16:07.530 回答
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
}
在此 StackOverflow 答案SYSTEM_VERSION_LESS_THAN()
中定义的位置。
于 2012-03-24T13:26:15.183 回答