gpt4 book ai didi

iphone - 仅在应用程序处于后台时获取位置更新

转载 作者:行者123 更新时间:2023-12-01 18:30:01 24 4
gpt4 key购买 nike

我正在尝试获取位置更新,尤其是在应用程序处于后台时。当应用程序进入后台时,应每隔n分钟发送一次位置更新
首先,我尝试使用前景,它工作正常。我将相同的代码复制到applicationDidEnterBackground,但无法打印位置更新。我不知道我被打到哪里,请帮助我。

在viewDidLoad中

- (void)viewDidLoad {

locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[locationManager startUpdatingLocation];
}


- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
int degrees = newLocation.coordinate.latitude;
double decimal = fabs(newLocation.coordinate.latitude - degrees);
int minutes = decimal * 60;
double seconds = decimal * 3600 - minutes * 60;
NSString *lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
latLabel.text = lat;
degrees = newLocation.coordinate.longitude;
decimal = fabs(newLocation.coordinate.longitude - degrees);
minutes = decimal * 60;
seconds = decimal * 3600 - minutes * 60;
NSString *longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
longLabel.text = longt;
}

我尝试将这些方法粘贴到AppDelegate中。它不起作用:(。帮助我

最佳答案

您不能简单地将代码粘贴到那里,并期望您的应用程序在后台运行。您必须将其注册为在后台运行的应用程序。请参阅this article中的实施长期运行的后台任务部分

关于iphone - 仅在应用程序处于后台时获取位置更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10136113/

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