Originalhttp://blog.csdn.net/nextstudio/article/details/40050095 ThemesiOS81. Modify Info
Added key:nslocationalwaysusagedescription and nslocationwheninuseusagedescription, the two key values will be used to describe the usage and positioning of the application for the duration of use, respectively. , these instructions are displayed in the user settings.
Info new key value pairs are as follows:
Application notes See:
2. Cllocationmanager initialization
Ios8cllocationmanager new instance methods Requestwheninuseauthorization and requestalwaysauthorization need to be called as needed at initialization time.
if ([Cllocationmanager locationservicesenabled]) { Self.locationmanage = [[Cllocationmanager alloc] init]; Self.locationManage.delegate =Self
Positioning frequency, the number of meters per self.locationManage.distanceFilter = 200;
Set positioning accuracy self.locationManage.desiredAccuracy = kcllocationaccuracybestfornavigation; Kcllocationaccuracybest;
Start Tracking Location
[Self.locationmanage startupdatinglacation]; if (system_version >= 8.0) { //Use period [self.locationmanage Requestwheninuseauthorization]; //Always //or [self.locationmanage requestalwaysauthorization] }} 3. Agent (Cllocationmanagerdelegate)
Failed to locate
-(void) Locationmanager: (Cllocationmanager *) Manager didfailwitherror: (nserror *) error
{
[Mbhuduntil HideAllHUDForView:self.window];
if (![ Shareddata SHAREINSTANCE].ISMB = = NO) {
[Mbhuduntil showhudtowindowwithtext:@ "Map location failed, please confirm that you have allowed the program to open the location service"];
}
}
Track the location agent method, which is executed each time the position changes (as long as it is positioned to the appropriate location)
-(void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) locations{
//If you do not need real-time positioning, use it even if you turn off location services
[_locationmanager stopupdatinglocation];
}
Add the following proxy methods:
- (void) Locationmanager: (Cllocationmanager *) Manager didchangeauthorizationstatus: (clauthorizationstatus) status{ Switch (status) { case kclauthorizationstatusnotdetermined: if ([self.locationmanage respondstoselector:@ Selector (requestalwaysauthorization)]) { [self.locationmanage Requestwheninuseauthorization]; } break; default: Break } /span>
IOS8 solution for locating problems