后台线程中的CLLocationManager [英] CLLocationManager in background thread

查看:71
本文介绍了后台线程中的CLLocationManager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个应用程序,因为我正在使用CLLocationManager类来获取更新的位置纬度和经度详细信息.但是我需要在单独的线程中使用此CLLocationManager.我编写了如下代码.

I am doing one application.In that i am using the CLLocationManager Class for getting the updated location latitude and longitude details.But i need to use this CLLocationManager in sepaate thread .I written my code like below.

- (void)viewDidLoad
{
 [NSThread detachNewThreadSelector:@selector(fetch) toTarget:self withObject:nil];
}
-(void)fetch
 {
    manager=[[CLLocationManager alloc]init];
    manager.delegate=self;
    manager.distanceFilter=kCLDistanceFilterNone;
    manager.desiredAccuracy = kCLLocationAccuracyBest;
    [manager startUpdatingLocation];

 }
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
       fromLocation:(CLLocation *)oldLocation
 {
   NSLog(@"%f",newLocation.coordinate.latitude);
   lbl.text=[NSString stringWithFormat:@"%f",newLocation.coordinate.longitude];
 }

.但是运行此代码时不会触发此委托方法.因此,请指导我如何在单独的线程中获取位置更新.

.But this delegate method is not fired when i run this code.So please guide me how to get the location updates in separate thread.

推荐答案

从启动相应位置服务的线程中调用委托对象的方法.该线程本身必须有一个活动的运行循环,就像在应用程序主线程中找到的那样. -来自苹果文件

The methods of your delegate object are called from the thread in which you started the corresponding location services. That thread must itself have an active run loop, like the one found in your application’s main thread. ——from apple document

这篇关于后台线程中的CLLocationManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆