1
我想通過程序找到設備空閒狀態。即找到設備未移動或移動的狀態。 我嘗試了以下加速計和核心運動API。但是,我無法從它給出的值中理解設備空閒狀態。尋找iOS設備空閒狀態
任何建議,將不勝感激。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
currentMaxAccelX = 0;
currentMaxAccelY = 0;
currentMaxAccelZ = 0;
currentMaxRotX = 0;
currentMaxRotY = 0;
currentMaxRotZ = 0;
value = 0;
self.motionManager = [[CMMotionManager alloc] init];
self.motionManager.accelerometerUpdateInterval = .2;
self.motionManager.gyroUpdateInterval = .2;
[self.motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue]
withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
[self outputAccelertionData:accelerometerData.acceleration];
if(error){
NSLog(@"%@", error);
}
}];
[self.motionManager startGyroUpdatesToQueue:[NSOperationQueue currentQueue]
withHandler:^(CMGyroData *gyroData, NSError *error) {
[self outputRotationData:gyroData.rotationRate];
}];
}
-(void)outputAccelertionData:(CMAcceleration)acceleration
{
self.accX.text = [NSString stringWithFormat:@"accX: %.2fg",acceleration.x];
if(fabs(acceleration.x) > fabs(currentMaxAccelX))
{
currentMaxAccelX = acceleration.x;
}
self.accY.text = [NSString stringWithFormat:@"accY: %.2fg",acceleration.y];
if(fabs(acceleration.y) > fabs(currentMaxAccelY))
{
currentMaxAccelY = acceleration.y;
}
if (fabs(acceleration.y) - fabs(value) > 0.2 || fabs(value) - fabs(acceleration.y) > 0.2)
{
NSLog(@"Not idle");
}
value = acceleration.y;
self.accZ.text = [NSString stringWithFormat:@"accZ: %.2fg",acceleration.z];
if(fabs(acceleration.z) > fabs(currentMaxAccelZ))
{
currentMaxAccelZ = acceleration.z;
}
self.maxAccX.text = [NSString stringWithFormat:@"maxAccX: %.2f",currentMaxAccelX];
self.maxAccY.text = [NSString stringWithFormat:@"maxAccY: %.2f",currentMaxAccelY];
self.maxAccZ.text = [NSString stringWithFormat:@"maxAccZ: %.2f",currentMaxAccelZ];
}
-(void)outputRotationData:(CMRotationRate)rotation
{
self.rotX.text = [NSString stringWithFormat:@"rotX: %.2fr/s",rotation.x];
if(fabs(rotation.x) > fabs(currentMaxRotX))
{
currentMaxRotX = rotation.x;
}
self.rotY.text = [NSString stringWithFormat:@"rotY: %.2fr/s",rotation.y];
if(fabs(rotation.y) > fabs(currentMaxRotY))
{
currentMaxRotY = rotation.y;
}
self.rotZ.text = [NSString stringWithFormat:@"rotZ: %.2fr/s",rotation.z];
if(fabs(rotation.z) > fabs(currentMaxRotZ))
{
currentMaxRotZ = rotation.z;
}
self.maxRotX.text = [NSString stringWithFormat:@"maxRotX: %.2f",currentMaxRotX];
self.maxRotY.text = [NSString stringWithFormat:@"maxRotY: %.2f",currentMaxRotY];
self.maxRotZ.text = [NSString stringWithFormat:@"maxRotZ: %.2f",currentMaxRotZ];
}
「我無法從它給出的值中理解設備空閒狀態。」它給了什麼價值? – matt 2015-04-02 17:43:51
你能建議我所嘗試的是正確的方法嗎?你能否建議一些方法在iOS設備上查找設備空閒時間? – Stella 2015-04-06 05:30:29
如果通過閒置,您的意思是_not moving _...請將問題文本更改爲使用單詞** stationary **代替空閒_....用於電話(或一般電子設備)空閒狀態是指沒有正在運行的程序或一般沒有數字活動)等。 – lukya 2015-04-10 18:59:23