CoreMotion Framework - PullRequest
       0

CoreMotion Framework

0 голосов
/ 16 марта 2011

Я недавно делал компас, чтобы задействовать каркас CoreMotion, но я долго проверял, не нашел информации о том, как реализовать на этой платформе эффект компаса, надеясь получить помощь каждого.

Ответы [ 2 ]

2 голосов
/ 17 мая 2011
0 голосов
/ 25 июня 2014

Мой "Helloworld" CoreMotion:

1) Добавить CoreMotion.framework

2) в файле .h:

#import <CoreMotion/CoreMotion.h>

3) в файле .m:

CMMotionManager *myMotionManager= [[CMMotionManager alloc] init];
myMotionManager.deviceMotionUpdateInterval = 1/60;
[myMotionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXMagneticNorthZVertical  toQueue:[NSOperationQueue currentQueue] withHandler:^(CMDeviceMotion *motion, NSError *error) {
     double x = myMotionManager.deviceMotion.magneticField.field.x;
     double y = myMotionManager.deviceMotion.magneticField.field.y;
     double z = myMotionManager.deviceMotion.magneticField.field.z;
    NSLog(@"Strength of Earth's magnetic field= %8.2f",sqrt(x*x+y*y+z*z));
    myLabel.text = [NSString stringWithFormat:@"%8.2f", sqrt(x*x+y*y+z*z)];
}];
...