CoreLocation location of iOS iOS9.0, ios9.0corelocation

Source: Internet
Author: User

CoreLocation location of iOS iOS9.0, ios9.0corelocation
I. Introduction

  • If iOS9.0 is in the foreground authorization status, the user location cannot be obtained in the background by default.
    • What should I do if I authorize the app to get the background location?
      • You can set the following attribute to YES to continue obtaining the background location, but blue bars will appear.
      • Note: You must set the corresponding background mode. Select the background mode: location updates.
        @property(assign,nonatomic) BOOL allowsBackgroundLocationUpdates
  • Note: iOS9.0 can be used to request the user location at a time.

    -(Void) requestLocation // successful call, location array, elements sorted by time-(void) locationManager :( nonnull CLLocationManager *) manager didUpdateLocations :( nonnull NSArray <CLLocation *> *) locations // call failure-(void) locationManager :( nonnull CLLocationManager *) manager didFailWithError :( nonnull NSError *) error
    • RequestLocation:
      • Sort by positioning accuracy from low to high and locate them one by one. If the obtained location is not the most accurate, the agent will tell the outside world after locating timeout (the-locationManager: didFailWithError: method must be implemented)
      • It cannot be used together with the startUpdatingLocation Method
II. Implementation Step 1. Foreground Positioning
  • 1. Import the CoreLocation framework and the corresponding primary header file
     #import <CoreLocation/CoreLocation.h>
  • Create a CLLcationManager object, set the proxy request to the foreground to locate and authorize, and configure the KEY

    Configure KEY. png
    _locationM = [[CLLocationManager alloc] init];  _locationM.delegate = self;  if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0)       {          [_locationM requestWhenInUseAuthorization];      }
  • 3. Call the startUpdatingLocation method of the CLLcationManager object to update the user location.
    [_locationM startUpdatingLocation];
  • 4. Implement proxy methods and receive location parameters
    -(void)locationManager:(nonnull CLLocationManager *)manager didUpdateLocations:(nonnull NSArray<CLLocation *> *)locations
2. Background Positioning
  • Solution 1: When the APP is in the foreground positioning authorization scenario, check the background running mode update locations (for example), and call the following method to set to allow background Positioning


    Select a model. PNG
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 9.0) {   _locationM.allowsBackgroundLocationUpdates = YES;}
    • Note: If the APP is in the background, blue lines will appear.
  • Solution 2: Request the frontend and backend to locate the authorization and configure the KEY

    [_locationM requestAlwaysAuthorization];



Text/iOS _ success transcript (simplified author)
Link: http://www.jianshu.com/p/a9a94cbcb775
Copyright belongs to the author. For reprinted content, contact the author for authorization and mark "author of simplified book ".

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.