【问题标题】:unable to implement CMMotionManager with ios app无法使用 ios 应用程序实现 CMMotionManager
【发布时间】:2014-11-04 11:40:53
【问题描述】:

如果我们倾斜设备,我正在尝试更改 UILabel 值,因为我正在尝试实现 CMMotionManager 但它对我不起作用,这是我正在使用的代码,

我在 lib 中添加了 CoreMotion。

#import <CoreMotion/CoreMotion.h>

 CMMotionManager *motionManager = [[CMMotionManager alloc] init];
    motionManager.accelerometerUpdateInterval = .2;

    [motionManager startAccelerometerUpdates];

    if ([motionManager isAccelerometerAvailable] == YES)
    {

        NSOperationQueue *queue = [[NSOperationQueue alloc] init];
        [queue setMaxConcurrentOperationCount:1];

        [motionManager startAccelerometerUpdatesToQueue:queue  withHandler:^(CMAccelerometerData *data, NSError *error)
         {

             CMAcceleration acceleration = data.acceleration;


             if(acceleration.y < -0.25) { // tilting the device to the right

                 [self setTextforlabel:@"right"];

             } else if (acceleration.y > 0.25) { // tilting the device to the left

                                  [self setTextforlabel:@"left"];
             }
         }];
    }

这里有什么问题,isAccelerometerAvailable 总是假的,

startAccelerometerUpdatesToQueue 它不会触发。

任何人都可以帮我解决这个问题或有任何其他方法来处理倾斜设备。

【问题讨论】:

  • 我知道了,对于倾斜,我们需要检查 DeviceMotion 及其在 ios 7 中对我有用,但在 ios6 中没有,对此有何评论?

标签: ios accelerometer cmmotionmanager


【解决方案1】:

您是在设备上运行它还是在刺激器中运行加速度计在刺激器中不起作用

【讨论】:

  • 我已经检查了设备
猜你喜欢
  • 2018-04-12
  • 2019-11-09
  • 2014-07-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多