gpt4 book ai didi

ios - didUpdateHeading 未调用

转载 作者:可可西里 更新时间:2023-11-01 04:45:35 24 4
gpt4 key购买 nike

我想用罗盘来更新航向。但是我的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com