iPhone 4中的CMMotionManager和陀螺仪

8
我想简单地使用NSLog输出新iPhone 4陀螺仪的输出。但是在阅读文档并按照示例代码进行操作后,我出现了以下错误。
ERROR,Time,300635803.946,Function,"CLLoggingSetFile",could not open locations log /var/mobile/Library/Caches/CoreMotion/CoreMotion.log

即使我只是独立地使用[[CMMotionManager alloc] init];来设置我的motionManager对象,而没有其他代码,我仍然会收到错误信息。
这是我的.h文件。
#import <UIKit/UIKit.h>
#import <CoreMotion/CoreMotion.h>

@interface GyroTest0ViewController : UIViewController {
    CMMotionManager *motionManager;
    NSOperationQueue *opQ;
}

@end

这是我的.m文件。

- (void)viewDidLoad {
    [super viewDidLoad];

    // the error occurs even just with this line on its own
    motionManager = [[CMMotionManager alloc] init]; 

    if (motionManager.gyroAvailable) {
        motionManager.gyroUpdateInterval = 1.0/60.0;
        [motionManager startGyroUpdates];
        opQ = [[NSOperationQueue currentQueue] retain];
        CMGyroHandler gyroHandler = ^ (CMGyroData *gyroData, NSError *error) {
            CMRotationRate rotate = gyroData.rotationRate;
            NSLog(@"rotation rate = [%f, %f, %f]", rotate.x, rotate.y, rotate.z);
        };
    } else {
        NSLog(@"No gyroscope on device.");
        [motionManager release];
    }
}

任何帮助和/或源代码,以简单地记录iPhone 4陀螺仪数据将不胜感激。非常感谢!

这是一个没有影响应用程序运行的错误。 - twerdster
1
iOS 4.2发布后,错误信息消失了。我想我们可以关闭这个问题了。 - Kay
当我尝试记录“态度”时,我会收到相同的错误,但这个错误似乎并没有引起实际问题:NSLog可以正常工作。 - RawMean
3个回答

8

尝试这个,

    motionManager.gyroUpdateInterval = 1.0/60.0;
    [motionManager startGyroUpdatesToQueue:[NSOperationQueue currentQueue]
                               withHandler: ^(CMGyroData *gyroData, NSError *error)
                                            {
                                                CMRotationRate rotate = gyroData.rotationRate;
                                                NSLog(@"rotation rate = [%f, %f, %f]", rotate.x, rotate.y, rotate.z);
                                            }];

3

对于WWDC示例代码:

  • 登录ADC
  • 点击WWDC 2010会话视频
  • 在iTunes中查看
  • 在那里您可以找到示例代码链接(230 MB)


2

有关这个问题的任何结果吗?即使我使用WWDC茶壶演示代码,我仍然会遇到相同的错误。我提交了一个错误报告(8382659)。

顺便说一下,当我使用Joshua Weinberg描述的推送方法时,我也会遇到相同的错误。

更新:苹果已确认该错误,但提到了一个我找不到的重复问题8173937。希望它能在下一个版本中得到修复。


1
iOS 4.2发布后,错误信息消失了。我认为我们可以关闭这个问题。(Kay)。 - James Beith

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接