Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone CMMotionManager-仅使用CMMotionManager获取标题_Iphone_Ios_Ipad_Cmmotionmanager - Fatal编程技术网

Iphone CMMotionManager-仅使用CMMotionManager获取标题

Iphone CMMotionManager-仅使用CMMotionManager获取标题,iphone,ios,ipad,cmmotionmanager,Iphone,Ios,Ipad,Cmmotionmanager,我已经设法使用CLLocationManager获得指南针航向,但因为我的应用程序已经使用CMMotionManager,所以我想专门使用CMMotionManager测量航向 像所有Apple模糊文档一样,您必须猜测如何使用它们的API 我试着用这个来测量航向 [self.motionManager setMagnetometerUpdateInterval:1.0/30.0]; //30 Hz [self.motionManager startMagnetometerUpdatesToQu

我已经设法使用CLLocationManager获得指南针航向,但因为我的应用程序已经使用CMMotionManager,所以我想专门使用CMMotionManager测量航向

像所有Apple模糊文档一样,您必须猜测如何使用它们的API

我试着用这个来测量航向

[self.motionManager setMagnetometerUpdateInterval:1.0/30.0]; //30 Hz

[self.motionManager startMagnetometerUpdatesToQueue:[NSOperationQueue currentQueue] withHandler:^(CMMagnetometerData *magnetometerData, NSError *error) {
    CMMagneticField compass = magnetometerData.magneticField;
    NSLog(@"x: %f  y:%f  z:%f", compass.x, compass.y, compass.z);
}];
问题是该块只运行几秒钟,然后停止运行

有没有关于如何专门使用CMMotionManager测量标题的示例


谢谢。

如果不尝试这样做,我建议使用
[NSOperationQueue mainQueue]
而不是currentQueue。通常,您只能从操作中调用currentQueue以获取对启动它的队列的引用。

如果不实际尝试此操作,我建议使用
[NSOperationQueue mainQueue]
而不是currentQueue。通常,您只能从操作中调用currentQueue以获取对启动它的队列的引用。

我建议您不要调用
start…UpdatesToQueue:withHandler:
。这需要使用后台线程,并且管理起来非常棘手。你可能只是把所有的东西都打在主线上。这是一种先进的技术,你不需要它

相反,只需
启动
,然后使用NSTimer或类似工具反复轮询CMMotionManager。

我建议您不要调用
启动…更新队列:withHandler:
。这需要使用后台线程,并且管理起来非常棘手。你可能只是把所有的东西都放在主线上。这是一种先进的技术,你不需要它


相反,只需
启动
,然后使用NSTimer或类似工具反复轮询CMMotionManager即可。

显然最好的方法是使用CoreLocation,直到苹果公司创建了合适的文档。

显然最好的方法是使用CoreLocation,直到苹果公司创建了像样的文档。

您是否强烈引用self.motionManager?您是否强烈引用self.motionManager?