gpt4 book ai didi

苹果手机 : using Background location services is stopped after a little time

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:50:32 24 4
gpt4 key购买 nike

我正在尝试获取位置并将其与在线位置进行比较所有这些都在后台发生我创建的方法使用后台定位服务工作正常,但大约一分钟后,状态栏中的位置图标消失并且该方法不再被调用

这是代码

- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {


double lat = newLocation.coordinate.latitude;
double lon = newLocation.coordinate.longitude;
NSURL * locationURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://somedomainname.com/iphoneLocation?lat=%f&lon=%f",lat,lon]];
NSData * responseData = [NSData dataWithContentsOfURL:locationURL];
NSString* aStr;
aStr = [[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding];



if ([aStr isEqualToString:@"out Of Any Knowen Range"] ){
UILocalNotification *notify =[[UILocalNotification alloc] init];
notify.alertAction = [[NSString alloc] initWithString: @"View"];
notify.fireDate=nil;
notify.alertBody = [NSString stringWithFormat:@"New Data Occured"];
notify.soundName = UILocalNotificationDefaultSoundName;
NSLog(@"Local notification should display");
[[UIApplication sharedApplication] presentLocalNotificationNow:notify];
}

}

在 viewDid 加载中我使用的是这样的东西

locationManager = [[CLLocationManager alloc] init];

locationManager.desiredAccuracy = kCLLocationAccuracyBest;

locationManager.delegate = self;

[locationManager startUpdatingLocation];

CLLocation *userLocation = [locationManager location];

这到底是怎么回事

最佳答案

您需要修改您的 AppName-Info.plist 文件,添加一个键 Required background modes 和一个值为 App registers for location updates 的项目。另一件事我认为你应该在你连接在线时做,这可能不会很快发生,所以你在线连接,发布位置和等待响应的操作应该在另一个线程中开始,同时如果你从 CLLocationManager 收到另一个位置并且您之前的请求尚未完成以跳过发布新位置...

关于苹果手机 : using Background location services is stopped after a little time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11176755/

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