IOS 8 Targeting

Source: Internet
Author: User

1. First import the Corelocation Framework Setup Agent

Cllocationmanagerdelegate

2.

-(void) Initlocationmanager

{

BOOL isenable = [Cllocationmanager locationservicesenabled];

CGFloat Verson = [[Uidevice currentdevice].systemversion Doublevalue];//float

if (isenable) {

if (!_loactionmanager) {

_loactionmanager = [[Cllocationmanager alloc] init];

[_loactionmanager setdelegate:self];

_loactionmanager.desiredaccuracy = Kcllocationaccuracybest;

_loactionmanager.distancefilter = 20.0;//is positioned every 10 meters

if (Verson > 8.0f) {

[_loactionmanager requestalwaysauthorization];

}

[_loactionmanager startupdatinglocation];

}

}

else {

Alert (@ "Warm tip", @ "Current device positioning function is not turned on!", we recommend that you turn on location services in [Set]->[privacy]->[Location Services] on your mobile system and allow "XXXX community" to use location services ");

Return

}

}

3. To add two key values in a pist file

Nslocationalwaysusagedescription nslocationwheninuseusagedescription This two key value added in this directory application requires IPhone Environment

4. Set up proxy methods

#pragma the Mark Proxy method

-(void) Locationmanager: (Cllocationmanager *) Manager

Didupdatelocations: (Nsarray *) Locations

{

Cllocation *currentlocation = [locations Lastobject];

Mjlog (@ "currentlocation = =%@", currentlocation);

Create location

Clgeocoder *revgeo = [[Clgeocoder alloc] init];

[Revgeo reversegeocodelocation:currentlocation completionhandler:^ (Nsarray *placemarks, NSError *error) {

Geo-editing

if (!error && [placemarks count] > 0) {

Nsdictionary *dict = [[Placemarks objectatindex:0] addressdictionary];

_currentposition = [dict objectforkey:@ "City"];

Mjlog (@ "City Address:%@", _currentposition); }

else {

Alert (@ "Warm tip", @ "Get location failed");

Mjlog (@ "error:%@", error); }

}];

}

-(void) Locationmanager: (Cllocationmanager *) Manager

Didfailwitherror: (Nserror *) error

{

Mjlog (@ "error:%@", [Error localizeddescription]);

}

IOS 8 Targeting

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.