In IOS8, Apple has forced the developer to get the user's authorization when requesting location services, and there is an indication icon in the iOS status bar that prompts the user whether the location service is being used by the current app. In addition, in IOS8, Apple has further improved location services, allowing developers to request location services to provide users with more transparency. In addition, IOS8 allows app developers to call the new "Access monitoring" feature, allowing the app to get more location data when the user allows it.
650) this.width=650; "alt=" Ios8_location_alert.png "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd; "/>
IOS8 previously used corelocation positioning
1, first defines a global variable used to record Cllocationmanager objects, introducing corelocation.framework using #import <corelocation/corelocation.h>
@property (nonatomic, strong) Cllocationmanager *locationmanager;
2. Initialize the Cllocationmanager and start positioning
Self.locationmanager = [[Cllocationmanager alloc]init];_locationmanager.delegate = self;_ Locationmanager.desiredaccuracy = Kcllocationaccuracybest;_locationmanager.distancefilter = 10; [_locationmanager startupdatinglocation];
3, the implementation of Cllocationmanagerdelegate agent method
(1) Gets the location data, returns an array of cllocation, typically using one of the
|
-(void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) locations{cllocation * currlocation = [Locations Lastobject]; NSLog (@ "Longitude =%f latitude =%f height =%f", currLocation.coordinrdinate.longitude, Currlocation.altitude);} |
(2) A callback method to get the user's location data failed, which notifies the user
|
- (void) Locationmanager: (cllocationmanager *) Manager didfailwitherror: (NSError *) error{ if ([error code] == kclerrordenied) { //Access Denied } if ([Error code] == kclerrorlocationunknown) { //cannot get location information } } |
4, viewwilldisappear Close positioning
|
-(void) Viewwilldisappear: (BOOL) animated{[Super viewwilldisappear:animated]; [_locationmanager stopupdatinglocation]; } |
Using corelocation positioning in iOS8
1, before using corelocation need to call the following function "IOS8 dedicated":
IOS8 has made some modifications to the positioning, including the method of locating authorization, Cllocationmanager adds the following two methods:
(1) Always allow access to location information
- (void)requestAlwaysAuthorization;
(2) Allow access to location data during use of the application
- (void)requestWhenInUseAuthorization;
Examples are as follows:
|
Self.locationmanager = [[Cllocationmanager alloc]init];_locationmanager.delegate = self;_ Locationmanager.desiredaccuracy = Kcllocationaccuracybest;_locationmanager.distancefilter = 10; [_locationmanager requestalwaysauthorization];//Add this sentence [_locationmanager startupdatinglocation]; |
2. Add the following configuration in the Info.plist file:
(1)NSLocationAlwaysUsageDescription
(2)NSLocationWhenInUseUsageDescription
tick show Raw keys/values to add ]:
650) this.width=650; "alt=" Ios8_location_info_plist.png "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd; "/>650) this.width=650, "src=" Http://s3.51cto.com/wyfs02/M02/54/77/wKioL1SD39uxLYz3AALsEEiEL6E195.jpg "title=" 74e9d08b-434a-4916-9981-e41ef482d6e7.png "alt=" Wkiol1sd39uxlyz3aalseeiel6e195.jpg "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/54/79/wKiom1SD34iRkzh-AANtBn50l54602.jpg "title=" 6ab8e125-5c7b-44d6-b2c6-94cc787b31f3.png "alt=" Wkiom1sd34irkzh-aantbn50l54602.jpg "/>
1, "Meet the Change of Ios8–corelocation"
2. "Core location of iOS development"
3, "IOS8 under the position of authorization"
This article is from "Xiao Liu _blog" blog, please be sure to keep this source http://liuyafang.blog.51cto.com/8837978/1587258
Using corelocation positioning in iOS8