Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I check if a Gyroscope is present on device?

Just wondering can I check if the device (iPhone, iPad, iPod i.e. iOS devices) has a Gyroscope ?

like image 648
user757812 Avatar asked Jun 02 '11 18:06

user757812


People also ask

Do all Android phones have a gyroscope?

Most Android-powered devices have an accelerometer, and many now include a gyroscope.

Do all phones have gyroscopes?

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.

What devices use gyroscope?

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…


3 Answers

- (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/

like image 90
Saurabh Avatar answered Oct 17 '22 17:10

Saurabh


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.

like image 36
Andrew Theis Avatar answered Oct 17 '22 15:10

Andrew Theis


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.

like image 1
codeperson Avatar answered Oct 17 '22 16:10

codeperson