저는 Apple의 Event Handling Guide for iOS에서 일하고 있습니다. startAccelerometerUpdates
근처에 설명 된 끌어 오기 메서드를 사용하고 있습니다. 내가 센서에서 한번만 읽을 필요가 있기 때문에 끌어 당기는 방법은 내 목적에 잘 맞습니다.CCMotionManager, accelerometerData, gyroData, magnetometerData return nil
iPhone 4, iPad Mini 및 iPad Retina에서 아래 코드에 accelerometerData
, gyroData
및 magnetometerData
전화가 걸려 오는 중입니다. isAccelerometerAvailable,
isGyroAvailable , and
isMagnetometerAvailable each return
YES`입니다. 두 가지 질문 :
startAccelerometerUpdates
과 startGyroUpdates
의 결과는 어떻게 결정됩니까? 그것들은 void
함수이기 때문에 결코 실패 할 수 없다고 생각할 수 있습니까? 그렇지 않으면 BOOL
을 던지거나 반환합니다.
accelerometerData
, gyroData
및 magnetometerData
으로 전화하면 마지막 오류가 어떻게 발생합니까?
EDIT : 데이터를 센서에서 빼내려면 [NSThread sleepForTimeInterval:0.150f]
으로 전화해야했습니다. 센서가 유효한 데이터를 생성하지 않습니다.
세 번째 질문은 하드웨어가있을 때 데이터가 도착하도록 잠시 멈추어야하는 시간입니다.
미리 감사드립니다.
static CryptoPP::RandomPool pool;
static dispatch_once_t once = 0;
dispatch_once(&once, ^{
CryptoPP::SecByteBlock seed(32);
CryptoPP::OS_GenerateRandomBlock(true, seed.data(), seed.size());
pool.IncorporateEntropy(seed.data(), seed.size());
});
// First, send in all the uninitialized data. Then:
// sesnors[0,1,2] use accelerometer, if available
// sesnors[3,4,5] use gyroscope, if available
// sesnors[6,7,8] use magnetometer, if available
CryptoPP::SecBlock<double> sensors(3 * 3);
pool.IncorporateEntropy(sensors.BytePtr(), sensors.SizeInBytes());
CMMotionManager* mgr = [[CMMotionManager alloc] init];
if(mgr) {
[mgr startAccelerometerUpdates];
[mgr startGyroUpdates];
[mgr startMagnetometerUpdates];
[NSThread sleepForTimeInterval:0.150f];
if([mgr isAccelerometerAvailable]) {
CMAccelerometerData* accelData = [mgr accelerometerData];
if(accelData) {
sensors[0] = [accelData acceleration].x;
sensors[1] = [accelData acceleration].y;
sensors[2] = [accelData acceleration].z;
}
}
if([mgr isGyroAvailable]) {
CMGyroData* gyroData = [mgr gyroData];
if(gyroData) {
sensors[3] = [gyroData rotationRate].x;
sensors[4] = [gyroData rotationRate].y;
sensors[5] = [gyroData rotationRate].z;
}
}
if([mgr isMagnetometerAvailable]) {
CMMagnetometerData* magnetData = [mgr magnetometerData];
if(magnetData) {
sensors[6] = [magnetData magneticField].x;
sensors[7] = [magnetData magneticField].y;
sensors[8] = [magnetData magneticField].z;
}
}
pool.IncorporateEntropy(sensors.BytePtr(), sensors.SizeInBytes());
[mgr stopMagnetometerUpdates];
[mgr stopGyroUpdates];
[mgr stopAccelerometerUpdates];
[mgr release], mgr = nil;
}
감사합니다. Abhi. 나는'setAccelerometerUpdateInterval'와 친구들없이 시도했다. 어떻게 정보를 즉시 받기 시작합니까 (이러한 설정을 사용하지 않으면 센서에서 아무것도 얻을 수 없습니다). 오류 정보를 가져 오는 방법은 무엇입니까? – jww
다시 한번 감사드립니다. Abhi. 나는 이것이 정확하다는 것을 믿지 않는다 : "당신은 실제로 약 0.00000000001 초를 기다리고있다". 문서에 따르면 "간격 단위는 초"입니다. – jww
다시 한번 감사합니다. Abhi. "메인 스레드가 유휴 상태 일 때만 업데이트를받을 것입니다." 내가 작업하고있는 문서에는 유휴 상태는 언급되어 있지 않습니다. (내 참조는 첫 단락에 있습니다). – jww