iphone - CLLocationManager never calls delegate methods -


hi i'm playing around locations on iphone , right start ran problems. i've localized problem , determined it's cllocationmanager that's bugging me.

so developed simple application. have view controller cllocationmanager in it. on view did load initialize cllocationmanager , start updating. i've implemented 2 methods didfailwitherror , didupdatetolocation.

i've read lot of questions , have learned fare this. have retain cllocationmanager during initialization. it's wise set cllocationmanagers delegate nil during unloading of view (something messages passing cllocationmanager because framework retains , it's never release)

all in cant find decent explanation on , how make work.

here's code if figure out appreciate it. viewcontrollers header file

#import <uikit/uikit.h> #import <corelocation/corelocation.h>  @interface corelocationviewcontroller : uiviewcontroller <cllocationmanagerdelegate> {     cllocationmanager *locmanager; }  @property (nonatomic, retain) cllocationmanager *locmanager;  @end 

viewcontroller .m file

#import "corelocationviewcontroller.h"   @implementation corelocationviewcontroller @synthesize locmanager;  - (void)viewdidload  {     [super viewdidload];      self.locmanager = [[cllocationmanager alloc] init];     locmanager.delegate = self;     [self.locmanager startupdatinglocation];      self.view.backgroundcolor = [uicolor graycolor]; }  #pragma mark - #pragma mark location delegate  - (void)locationmanager:(cllocationmanager *)manager didfailwitherror:(nserror *)error {         nslog(@"in fail error"); }  - (void)locationmanager:(cllocationmanager *)manager didupdatetolocation:(cllocation *)newlocation fromlocation:(cllocation *)oldlocation {     nslog(@"in update location"); }   #pragma mark - #pragma mark memory management  - (void)didreceivememorywarning {     [super didreceivememorywarning]; }  - (void)viewdidunload  { self.locmanager.delegate = nil;     [super viewdidunload]; }   - (void)dealloc  {     [locmanager release];         [super dealloc]; }   @end 

btw: i'm using ios 4.2. i'm pointing out because read apple has changed location delegates in ios 4

in case, delegate never gets called because of threading problem

  • the thread operates locationmanager must have nsrunloop set
  • if use main thread, have runloop, need instantiate manager , use on main thread

read know more cllocationmanagerdelegate


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -