Just wondering can I check if the device (iPhone, iPad, iPod i.e. iOS devices) has a Gyroscope ?
Most Android-powered devices have an accelerometer, and many now include a gyroscope.
Most smartphones contain gyroscopes to detect the orientation of the screen and help figure out which way we're facing, but they have poor accuracy. That's why phones often incorrectly indicate which direction a user is facing during navigation.
Vibration Gyroscope sensors are used in the car navigation systems, Electronic stability control systems of vehicles, motion sensing for mobile games, camera-shake detection systems in digital cameras, radio-controlled helicopters, Robotic systems, etc…
- (BOOL) isGyroscopeAvailable
{
#ifdef __IPHONE_4_0
CMMotionManager *motionManager = [[CMMotionManager alloc] init];
BOOL gyroAvailable = motionManager.gyroAvailable;
[motionManager release];
return gyroAvailable;
#else
return NO;
#endif
}
See also my this blog entry to know you can check for different capabilities in iOS devices http://www.makebetterthings.com/blogs/iphone/check-ios-device-capabilities/
CoreMotion's motion manager class has a property built in for checking hardware availability. Saurabh's method would require you to update your app every time a new device with a gyroscope is released (iPad 2, etc). Here's sample code using the Apple documented property for checking for gyroscope availability:
CMMotionManager *motionManager = [[[CMMotionManager alloc] init] autorelease];
if (motionManager.gyroAvailable)
{
motionManager.deviceMotionUpdateInterval = 1.0/60.0;
[motionManager startDeviceMotionUpdates];
}
See the documentation for more info.
I believe the answers from @Saurabh and @Andrew Theis are only partially correct.
This is a more complete solution:
- (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
}
Where the SYSTEM_VERSION_LESS_THAN()
is defined in this StackOverflow answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With