Positioning problems on IOS8

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.