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?
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. PNGif ([[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 ".