Compiling on IOS 8 will show the following log:
Trying to start Mapkit location updates without prompting for location authorization. Must call-[cllocationmanager requestwheninuseauthorization] or-[cllocationmanager requestalwaysauthorization] First .
The search has been resolved as follows:
1, modify Info.plist:
New key value is Nslocationwheninuseusagedescription or nslocationalwaysusagedescription (here, I will add two), value can be empty, you can also set a Yes, However, my problem still can not be solved, eventually found the problem is that info.plist also need to include supported interface orientations this array field. Then the operation is resolved.
2. Modify the code:
Add a sentence before calling the method startupdatinglocation
if ([Locationmanager respondstoselector: @selector (requestwheninuseauthorization)]) { [Locationmanager Requestwheninuseauthorization];}
3. How to modify the original blog:
Locationmanager = [[Cllocationmanager alloc] init]; Locationmanager.delegate = self; Locationmanager.desiredaccuracy=kcllocationaccuracybest; if ([Locationmanager respondstoselector: @selector (requestwheninuseauthorization)]) { [Locationmanager Requestwheninuseauthorization]; } [Locationmanager startupdatinglocation];
-(void) Locationmanager: (Cllocationmanager *) Manager Didchangeauthorizationstatus: (clauthorizationstatus) Status {if ([Locationmanager respondstoselector: @selector (requestwheninuseauthorization)] && Status! = kclauthorizationstatusnotdetermined && Status! = Kclauthorizationstatusauthorizedwheninuse) | | (! [Locationmanager respondstoselector: @selector (requestwheninuseauthorization)] && Status! = kclauthorizationstatusnotdetermined && status = kclauthorizationstatusauthorized)) {NSString *mes Sage = @ "Your phone is not currently open for location services, so if you want to start the location service, please go to Settings------------Privacy Uialertview *alertview = [[Uialertview alloc] initwithtitle:@ "Unable to locate" Message:message delegate:nil cancelbuttontitle:@ " Make sure "Otherbuttontitles:nil"; [Alertview show]; }else {[Locationmanager startupdatinglocation]; }}
The above line is iOS 8 and the second line is below iOS 7 because kclauthorizationstatusauthorized is not available in iOS 8 at all.
Clauthorizationstatus status = [Cllocationmanager authorizationstatus]; if (status = = Kclauthorizationstatusauthorizedwheninuse | | status = = kclauthorizationstatusauthorized) { //start location} else { //Display warning}
iOS Dev-app when running on iOS 8 simulator, locate the card dead bug resolved