System authorization is required to use Cllocationmanager location service under IOS8

Source: Internet
Author: User

Recently, using the Cllocationmanager location service in ios8.0, I found that the old can't be located, and the items in the Settings menu are also in an unknown state. Remember that there was a popup box prompting the user whether to allow positioning, This has not been the case. The original ios8.0 under the location service needs to apply for authorization. The specific code is as follows:

1 if([Cllocationmanager locationservicesenabled]) {2 3Self.locationmanager =[[Cllocationmanager alloc] init];4 5_locationmanager.Delegate=Self ;6 7_locationmanager.desiredaccuracy = Kcllocationaccuracybest;//control the positioning accuracy, the higher the power consumption of the greater. 8 9_locationmanager.distancefilter = -;//controls the frequency of location service updates. Unit is "M"Ten   One [_locationmanager startupdatinglocation]; A  -    //under iOS 8.0 to authorize -  the    if([[[[Uidevice Currentdevice] systemversion] Floatvalue] >=8.0) -  -[_locationmanager requestwheninuseauthorization];//call this sentence, will pop up the Allow box. -  +}

Attention:

In the Info.plist file also add nslocationwheninuseusagedescription this key,value can be empty,

1 #pragmaMark-cllocationmanagerdelegate2 3- (void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) Locations {4 5   6 7Cllocation * Currlocation =[Locations Lastobject];8 9  Ten  OneNSLog (@"%@", [NSString stringWithFormat:@"%.3f", CurrLocation.coordinate.latitude]); A  -NSLog (@"%@", [NSString stringWithFormat:@"%.3f", CurrLocation.coordinate.longitude]); -  the}

System authorization is required to use Cllocationmanager location service under 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.