CLLocationManager in background thread

南楼画角 提交于 2019-12-08 06:21:26

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

Could you please tried with this.

 dispatch_async(newThread, ^(void) {

       [self fetch];
   }); 

hope you'll get solved problem.

in .h file

MainView *ctl;
NSMutableDictionary *dictSubPoses;

- (id)initWithCtl:(MainView*)_ctl;

in .m file

- (id)initWithCtl:(MainView*)_ctl
{
   if(self = [super init]) 
   {
      ctl = _ctl; //[_ctl retain];
   }

   return self;
}

- (void)main 
{
   [ctl performSelector:@selector(yourMethod) withObject:dictSubPoses];
}

in .h file

#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>

//Set Delegate  
    CLLocationManagerDelegate
// Declare
    CLLocationManager *locationManager;

in .m file

-(void)ViewDidLoad
{
    locationupadate=YES;
    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    locationManager.distanceFilter = 100.0f;
    [locationManager startUpdatingLocation];
}

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

     if(locationupadate)
     {
           NSLog(@"%f",newLocation.coordinate.latitude);
          lbl.text=[NSString stringWithFormat:@"%f",newLocation.coordinate.longitude];

     }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!