簡體   English   中英

適用和CoreMotion

[英]Apportable & CoreMotion

我正在嘗試讓我的游戲在Android上運行。 我已經將其與Apportable的免費版本進行了移植,並且效果很好,但是我還無法實現陀螺儀功能。

CMMotionManager被初始化,但運動更新從未開始(或至少handleDeviceMotion:從未被調用)。 運動管理器的isAccelerometerActive屬性始終為NO,但isAccelerometerAvailable為YES。

使用[NSOperationQueue mainQueue]也無濟於事。

這就是我初始化運動管理器的方式:

self.motionManager = [[CMMotionManager alloc] init];
self.motionManager.gyroUpdateInterval = .2;

[self.motionManager startDeviceMotionUpdatesToQueue:[[NSOperationQueue alloc] init]
                                                withHandler:^(CMDeviceMotion *motion, NSError *error) {
                                                    dispatch_async(dispatch_get_main_queue(), ^{
                                                        [self handleDeviceMotion:motion];
                                                    });
                                                }];

它向logcat產生以下消息:

E/Sensors (  507): HAL:ERR open file /sys/bus/iio/devices/iio:device0/dmp_event_int_on to write with error 2
E/Sensors (  507): HAL:ERR can't disable DMP event interrupt

我不知道這意味着什么...我正在Asus Nexus 7上測試該應用程序。

將CoreMotion與Apportable結合使用時,我需要做些特別的事情嗎?

編輯: 這是我創建一個簡單的測試項目,以演示該問題。

CoreMotion應該與apportable一起使用。 這是我在Nexus 7(2012)上測試過的簡化的初始化和使用范例。

self.motionManager = [[CMMotionManager alloc] init];
[self.motionManager startDeviceMotionUpdates];

self.motionTimer = [NSTimer scheduledTimerWithTimeInterval:0.2 
    target:self 
    selector:@selector(handleDeviceMotion) 
    userInfo:nil 
    repeats:YES];

代替使用startDeviceMotionUpdatesToQueue: withHandler:處理運動事件,嘗試在handleDeviceMotion方法中顯式訪問deviceMotion屬性,該方法將由重復計時器調用。

-(void) handleDeviceMotion {
    CMDeviceMotion *motion = [self.motionManager deviceMotion];
    // use motion data accordingly
}    

而且,別忘了在完成后停止更新!

[self.motionManager stopDeviceMotionUpdates];

特別是對於這種設備運動,我們(希望)在下一次SDK更新中解決了一系列相當分層的問題。 我已經實現了偏航,俯仰和滾動,它們似乎給出了相對合理的值。 如果仍然有問題,請發送電子郵件至sdk(@)apportable.com(顯然要刪除家長)並提及我。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM