objective c - iOS 8 : Mapkit error throws an : Must call -[CLLocationManager requestWhenInUseAuthorization] -


in ios 8.3 xcode 6.3.2, when i'm launching map, throws following error:

trying start mapkit location updates without prompting location authorization. must call -[cllocationmanager requestwheninuseauthorization] or -[cllocationmanager requestalwaysauthorization] first. 

i have done , follow every step launch map in ios8 app, here code this:

//viewcontroller default function set mapview , function find user current location.    - (void)viewdidload {     [super viewdidload];     // additional setup after loading view, typically nib.      [[self otlmapview] setshowsuserlocation:yes];     self.otlmapview.delegate = self;      [self updateusercurrentlocation]; }  //this function used fine user current location. -(void)updateusercurrentlocation {     // create location manager     self.locationmanager = [[cllocationmanager alloc] init];      // set delegate receive location callbacks     self.locationmanager.delegate = self;     self.locationmanager.desiredaccuracy = kcllocationaccuracybest;      if ([self.locationmanager respondstoselector:@selector(requestwheninuseauthorization)])     {         [self.locationmanager requestwheninuseauthorization];     }      // start location manager     [self.locationmanager startupdatinglocation];      [self.locationmanager requestwheninuseauthorization]; }  #pragma mark location callback method  // wait location callbacks - (void)locationmanager:(cllocationmanager *)manager didupdatelocations:(nsarray *)locations {     nslog(@"current location%@", [locations lastobject]); } 

what doing wrong?

i assume you've correctly set info.plist already. try this:

- (void)viewdidload {   [self updateusercurrentlocation];   }  - (void)updateusercurrentlocation {   if (nil == locationmanager) {     locationmanager = [[cllocationmanager alloc] init];   }    locationmanager.delegate = self;    // part added due location authorization issue on ios8   // see more at: http://nevan.net/2014/09/core-location-manager-changes-in-ios-8/   if ([self._locationmanager respondstoselector:@selector(requestwheninuseauthorization)]) {     [self._locationmanager requestwheninuseauthorization];   }    self.mapview.showsuserlocation = yes;    [locationmanager startupdatinglocation];    cllocation *currentlocation = locationmanager.location;   if (currentlocation) {     pawappdelegate *appdelegate = [[uiapplication sharedapplication] delegate];     appdelegate.currentlocation = currentlocation;   }   } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -