(75) Corelocation (i) obtaining authorization on iOS7 and IOS8 devices

Source: Internet
Author: User

Apple has updated the Corelocation authorization acquisition method on IOS8, on the original basis, not only need to invoke the authorization function, but also need to configure the Info.plist accordingly.

Getting latitude and longitude on iOS is Corelocationmanager, which comes from the corelocation.framework framework, which should include the frame's total header file:

#import <CoreLocation/CoreLocation.h>

The general is to create the manager first, then become its agent, for IOS7, directly callStartupdatinglocation can start listening, and for iOS8, you also need to call a method to authorize, depending on the use of different, there are two kinds of authorization, respectively, the use of the location and continue to obtain the location, according to the different needs of the call:

[Self.manager requestalwaysauthorization]; [Self.manager requestwheninuseauthorization];
Generally direct access to the first, the application of a wider range.

In addition, add two keys to Info.plist, and the value of string,string is the description that is displayed when requesting authorization:

Corresponds to two authorizations, with Nslocationwheninuseusagedescription and nslocationalwaysusagedescription two keys.

Each time the application is opened, an agent method is invoked to determine the authorization status: This method determines whether the authorization is successful, and if successful, calls startupdatinglocation to start positioning.

Call-(void) Locationmanager when authorization status changes: (Cllocationmanager *) Manager Didchangeauthorizationstatus: ( Clauthorizationstatus) status{/* typedef ns_enum (int, clauthorizationstatus) {//User have not yet made a Cho  Ice with regards to the application kclauthorizationstatusnotdetermined = 0,//This application is  Not authorized to use location services. Due/to active restrictions in location services, the user cannot change/ Personally denied authorization kclauthorizationstatusrestricted,//User have explicitly denied Auth        Orization for the application, or//location services is disabled in Settings. Kclauthorizationstatusdenied,//User have granted authorization to use their        /including monitoring for regions, visits, or significant location changes.     Kclauthorizationstatusauthorizedalways ns_enum_available (NA, 8_0),           User have granted authorization to use their location only if your app//is visible to them (it wil  L be made visible to them if you continue to//Receive location updates while in the background).        Authorization to use//launch APIs have not been granted. Kclauthorizationstatusauthorizedwheninuse ns_enum_available (NA, 8_0),//This value is deprecated, but was        Equivalent to the New-always value. Kclauthorizationstatusauthorized ns_enum_deprecated (10_6, NA, 2_0, 8_0, "Use Kclauthorizationstatusauthorizedalways" ) = kclauthorizationstatusauthorizedalways};*/switch (status) {case Kclauthorizationstatusauthorizedal            Ways:nslog (@ "Continued use authorization");            [Self.manager startupdatinglocation];        Break            Case Kclauthorizationstatusauthorizedwheninuse:nslog (@ "authorized in use");            [Self.manager startupdatinglocation];        Break  Case Kclauthorizationstatusdenied:          NSLog (@ "authorization denied");        Break            Case Kclauthorizationstatusnotdetermined:nslog (@ "Waiting for user Authorization");        Break    Default:break; }        }

Because the iOS7 directly start to obtain the location, so should be differentiated treatment of the two systems, with Uidevice to obtain the system version, for different systems for different processing, if it is iOS8 previous system, directly start to obtain the location:

-(void) viewdidload {    [super viewdidload];        1. Create Corelocationmanager    Cllocationmanager *manager = [[Cllocationmanager alloc] init];    Self.manager = Manager;    2. Become its agent    self.manager.delegate = self;        if ([[Uidevice currentdevice].systemversion Doublevalue] >= 8.0) {        [Self.manager requestalwaysauthorization];    }else{        //iOS8 previously directly began positioning        [Self.manager startupdatinglocation];    }    

To determine whether a successful start location, implement the Proxy methodLocationmanager:didupdatelocations: to observe.

See the following section for latitude, longitude, direction, and area judgments.



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

(75) Corelocation (i) obtaining authorization on iOS7 and IOS8 devices

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.