Before iOS7, we entered the program to prompt the user to open the location to do so, as follows:
Cllocationmanager * Locationmanager = [[cllocationmanager alloc] init]; //Create Location Manager
//locationmanager.delegate=_instance;
Locationmanager. Desiredaccuracy=kcllocationaccuracybest;
Locationmanager. distancefilter=100.0f;
//Location service is available
BOOL enable=[ cllocationmanager locationservicesenabled];
//Do you have location permissions
int status=[cllocationmanager authorizationstatus];
if (!enable | | status<3) {
//Request Permission
[Locationmanager requestwheninuseauthorization];
}
But after the iOS8, found that the location does not work, always prompt: 650) this.width=650; "Src=" http://s3.51cto.com/wyfs02/M02/4B/F2/wKioL1Q1_ 3gwxq89aaej-etu45o752.jpg "title=" 016c4c99-9e8c-4fb3-a14e-f08152804e06.png "alt=" wKioL1Q1_ 3gwxq89aaej-etu45o752.jpg "/>
iOS8 positioning is resolved as follows:
First define key in Info.plist: (Always authorize)nslocationalwaysusagedescription or authorize when using Nslocationwheninuseusagedescription
Inside the. h
Inherit code cllocationmanagerdelegate
Define Cllocationmanager *_locationmanager;
Inside the. M definition:
-(void) starttrackinglocation {
clauthorizationstatus status = [cllocationmanager authorizationstatus];
if (status = = kclauthorizationstatusnotdetermined) {
//Always authorize
[_locationmanager requestalwaysauthorization];
//One time per authorization
//[_locationmanager requestwheninuseauthorization];
}
Else if (status = = Kclauthorizationstatusauthorizedwheninuse | | Status = = kclauthorizationstatusauthorizedalways) {
[_locationmanager startupdatinglocation];
}
}
Implementing Code Callbacks
#pragma mark-cllocationmanager Delegate Methods
-(void) Locationmanager: (cllocationmanager *) Manager didchangeauthorizationstatus: ( Clauthorizationstatus) Status {
Switch (status) {
case kclauthorizationstatusauthorizedalways:
case kclauthorizationstatusauthorizedwheninuse:
NSLog(@ "Got authorization, start tracking Location");
[ self starttrackinglocation];
break;
case kclauthorizationstatusnotdetermined:
[_locationmanager requestalwaysauthorization];
break;
default:
break;
}
}
The call is as follows:
if (IOS8) {
_locationmanager = [[cllocationmanager alloc] init];
_locationmanager. Delegate = Self ;
[ self starttrackinglocation];
}
At the end of the implementation, click Allow to navigate:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/4B/F5/wKioL1Q2AjLh6ra9AAEmwOdLAiE207.jpg "title=" 1ea3d9ce-decd-4f23-a751-ddc6ff68c217.png "alt=" Wkiol1q2ajlh6ra9aaemwodlaie207.jpg "/>
Positioning problems on IOS8