我正在制作一个指南针应用程序,但是当我的函数[localManager startUpdatingHeading]
调用它时,它会自动调用该函数
-(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
但是第二个函数永远不会被调用,所以我的程序不起作用。我在我的设备上运行此代码,但什么也没发生。请帮我。
- (void)viewDidLoad
{
[super viewDidLoad];
CLLocationManager *locaManager = [[CLLocationManager alloc] init];
locaManager.desiredAccuracy = kCLLocationAccuracyBest;
locaManager.delegate = self;
locaManager.headingFilter = .5;
if ([CLLocationManager locationServicesEnabled] && [CLLocationManager
headingAvailable]) {
[locaManager startUpdatingHeading];
[locaManager startUpdatingLocation];
} else {
NSLog(@"Error");
}
}
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
if (newHeading.headingAccuracy > 0) {
float magneticHeading = newHeading.magneticHeading;
float trueHeading = newHeading.trueHeading;
label2.text = [NSString stringWithFormat:@"%f", magneticHeading];
label1.text = [NSString stringWithFormat:@"%f", trueHeading];
float heading = -1.0f * M_PI * newHeading.magneticHeading / 180.0f;
imagen.transform = CGAffineTransformMakeRotation(heading);
}
}