6

デバイス(iPhone、iPad、iPod、つまりiOSデバイス)にジャイロスコープがあるかどうかを確認できますか?

4

3 に答える 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と@AndrewTheisの回答は部分的にしか正しいとは思いません。

これはより完全な解決策です:

- (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 に答える