2
有没有办法获得钛中的陀螺仪数据?就像有一个API访问accelerometer数据。钛中的陀螺仪值
有没有办法获得钛中的陀螺仪数据?就像有一个API访问accelerometer数据。钛中的陀螺仪值
目前没有,但是有一种相对简单的方法可以向已经使用CoreMotion的现有模块添加一些代码。
本巴林堡的模块,可在这里:https://github.com/benbahrenburg/Ti.CoreMotion/使用CoreMotion公开步骤计数器。所以它已经有了引用的框架,以及模块的建立,构建等等。这是一件很难的事情。所以把它拉下来,确保你自己可以./build.py
,然后暴露陀螺仪。当你完成后发一个PR给他,并回馈给社区!
static const NSTimeInterval gyroMin = 0.01;
- (id)startGyro:(id)args {
// Determine the update interval
NSTimeInterval delta = 0.005;
NSTimeInterval updateInterval = gyroMin + delta;
// Create a CMMotionManager
CMMotionManager *mManager = [(APLAppDelegate *)[[UIApplication sharedApplication] delegate] sharedManager];
APLGyroGraphViewController * __weak weakSelf = self;
// Check whether the gyroscope is available
if ([mManager isGyroAvailable] == YES) {
// Assign the update interval to the motion manager
[mManager setGyroUpdateInterval:updateInterval];
[mManager startGyroUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMGyroData *gyroData, NSError *error) {
// TODO: Do something with gyroData.rotationRate.x, y, and z.
}];
}
return nil;
}
- (id)stopUpdates:(id)args {
CMMotionManager *mManager = [(APLAppDelegate *)[[UIApplication sharedApplication] delegate] sharedManager];
if ([mManager isGyroActive] == YES) {
[mManager stopGyroUpdates];
}
return nil;
}
切记:使用Core Motion,您必须在设备上测试和调试您的应用程序。 iOS模拟器不支持加速计或陀螺仪数据。