startDeviceMotionUpdatesToQueue的安全更新间隔:withHandler:? [英] Safe update interval for startDeviceMotionUpdatesToQueue:withHandler:?

查看:1370
本文介绍了startDeviceMotionUpdatesToQueue的安全更新间隔:withHandler:?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:添加了全局,现在正在运行。但我仍有疑虑..请继续阅读:)



我想在需要和使用时在Y轴上进行加速它在我的代码的不同部分。在这个例子中,我在while循环中使用它来进行测试..



我的代码正在运行,但我正在使用UpdateToQueue ...方法或者这是一种实现我想要的非正统方式吗?



我将更新间隔设置为30毫秒,你认为这是一个安全吗?更新间隔?我被告知在选择一个时应该小心,因为当前或以后的硬件/ iOS更新可能无法跟上这样的间隔这是真的吗?

  double myAcceleration; //一个全局.. 

- (无效)播放//我的主方法..
{
CMMotionManager * motionManager = [[CMMotionManager alloc] init];
motionManager.deviceMotionUpdateInterval = 0.03; //每30ms更新一次
[motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue mainQueue]
withHandler:^(CMDeviceMotion * motion,NSError * error)
{
myAcceleration = motion.userAcceleration.y;
}
];

while(!self.stopButtonPressed)
{
NSLog(@Y轴加速度为%f,myAcceleration);
}
}


解决方案

它可以这样使用。



关于时间间隔:当前最大更新限制为100Hz(每秒100次,一次加速度计更新为0.01秒),最小值是10Hz(AFAIK)。如果您在这样的范围内设置了时间间隔,那么苹果小工具的当前版本和下一版本肯定会受到支持。但你不能依赖默认的时间间隔,并祈祷它在任何地方都是一样的,因为苹果可能会改变最小和最大(例如一些新的IC芯片将支持500Hz刷新率)范围,因此默认也会改变。 / p>

EDIT: added a global and now it's working. But I still have my doubts.. Please read on :)

I want to get the acceleration exercised on the Y-axis whenever I need to and use it in different parts of my code. In this example I'm using it inside a while-loop for testing purposes..

My code is working but Am I using the the UpdateToQueue... method correctly or is this kind of an "unorthodox" way of achieving what I want?

I've set the Update Interval at 30 ms, do you think this is a "safe" update interval ? I was told that I should be careful when choosing one because current or later hardware/iOS updates might not be able to keep up with such an interval is this true?

double myAcceleration; // a global..

-(void) play // my "main" method..
{
    CMMotionManager *motionManager = [[CMMotionManager alloc] init];
    motionManager.deviceMotionUpdateInterval = 0.03; // update every 30ms
    [motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue mainQueue]  
                                       withHandler:^(CMDeviceMotion *motion, NSError *error) 
                                       {
                                           myAcceleration = motion.userAcceleration.y;
                                       }
    ];

    while(!self.stopButtonPressed)
    {
        NSLog(@"Y-Axis acceleration is %f", myAcceleration);
    }
}

解决方案

It is ok to use in such way.

And about time interval: current maximum update limit is 100Hz( 100 times per second, 0.01 second for one accelerometer update), and minimum is 10Hz( AFAIK ). if you have set time interval in such ranges it will surely be supported in current and next releases of apple gadgets. But you can't rely on default time interval and pray that it will be the same everywhere, cause apple may change min and max( ex. some new IC chip would support 500Hz refresh rate ) ranges, and so default would change too.

这篇关于startDeviceMotionUpdatesToQueue的安全更新间隔:withHandler:?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆