我使用CoreMotion
获得如下的摇动加速度值:
-(void)startAccelerometer {
[self.motionManager startAccelerometerUpdatesToQueue:[[NSOperationQueue alloc]init]
withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
[self outputAccelertionData:accelerometerData.acceleration];
if (error) {
NSLog(@"motion error:%@",error);
}
}];
}
-(void)outputAccelertionData:(CMAcceleration)acceleration {
double accelerameter =sqrt( pow( acceleration.x , 2 ) + pow( acceleration.y , 2 )
+ pow( acceleration.z , 2) );
if (accelerameter>2.3f) {
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:@"shaked" object:[NSValue value:&acceleration withObjCType:@encode(CMAcceleration)]];
});
}
}
在我的另一个glView控制器中,观察shaked
通知并执行render
内容,但它经常在[self.glContext presentRenderbuffer:GL_RENDERBUFFER];
行崩溃,请参阅堆栈跟踪:
有什么想法吗?