我想用罗盘来更新航向。但是我的 didUpdateHeading 没有调用。我是 iOS 的新手。请帮助任何帮助将不胜感激。
@interface ViewController : UIViewController<CLLocationManagerDelegate>
@property (nonatomic, retain) CLLocationManager *locationManager;
locationManager=[[CLLocationManager alloc] init];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.delegate=self;
//Start the compass updates.
[locationManager startUpdatingHeading];
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
NSLog(@"New magnetic heading: %f", newHeading.magneticHeading);
NSLog(@"New true heading: %f", newHeading.trueHeading);
}
最佳答案
您提供的代码(假设您在粘贴此处时没有更改任何内容)缺少运行第一部分的函数或代码块,我建议您将其放在 viewController
init 中,像这样:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
locationManager=[[CLLocationManager alloc] init];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.delegate=self;
//Start the compass updates.
[locationManager startUpdatingHeading];
}
return self;
}
关于ios - didUpdateHeading 未调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32134447/