ios - CLLocationManager weird behavior -


i have weird problem.

i have 2 classes:

  1. businessvc
  2. favoritesvc

in both of them show user current distance him specific point. in both of classes use exact same code that.

favoritesvc presented modal view controller.

for reason didupdatelocations / didupdatetolocation methods getting called in businessvc , not in favoritesvc.

i'm implementing cllocationmanagerdelegate delegate in both classes.

the code i'm using:

 -(void)viewdidload {      [super viewdidload];       [self locatedme]; }  -(void) locatedme{     nslog(@"locateme");     _locationmanager = [[cllocationmanager alloc] init];     [_locationmanager setdelegate:self];     [_locationmanager setdistancefilter:kcldistancefilternone]; // whenever move     [_locationmanager setdesiredaccuracy:kcllocationaccuracyhundredmeters]; // 100 m     [_locationmanager startupdatinglocation]; }   // ios6 -(void)locationmanager:(cllocationmanager *)manager didupdatelocations:(nsarray  *)locations {      cllocation * newlocation = [locations lastobject];     nsnumber *lat = [[nsnumber alloc] initwithdouble:newlocation.coordinate.latitude];     nsnumber *lon = [[nsnumber alloc] initwithdouble:newlocation.coordinate.longitude];      self.userlocation = [[cllocation alloc] initwithlatitude:[lat doublevalue] longitude:[lon doublevalue]];  }   // earlier ios6 - (void)locationmanager:(cllocationmanager *)manager didupdatetolocation:(cllocation *)newlocation fromlocation:(cllocation *)oldlocation{      nsnumber *lat = [[nsnumber alloc] initwithdouble:newlocation.coordinate.latitude];     nsnumber *lon = [[nsnumber alloc] initwithdouble:newlocation.coordinate.longitude];      self.userlocation = [[cllocation alloc] initwithlatitude:[lat doublevalue] longitude:[lon doublevalue]];      nslog(@"%@",self.userlocation); } 

ok! fixed running code on main thread using code:

-(void) locateme {     nslog(@"locateme");     dispatch_async(dispatch_get_main_queue(), ^{          _locationmanager = [[cllocationmanager alloc] init];          [_locationmanager setdelegate:self];          [_locationmanager setdesiredaccuracy:kcllocationaccuracybest]; // 100 m          [_locationmanager startupdatinglocation];          [_locationmanager startupdatingheading];      }); 

}


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -