if([CLLocationManagerlocationServicesEnabled]){#if__IPHONE_OS_VERSION_MAX_ALLOWED>__IPHONE_7_1//AsofiOS8,appsmustexplicitlyrequestlocationservicespermissions.INTULocationManagersupportsbothlevels,"Always"and"WhenInUse".//INTULocationManagerdetermineswhichlevelofpermissionstorequestbasedonwhichdescriptionkeyispresentinyourapp'sInfo.plist//Ifyouprovidevaluesforbothdescriptionkeys,themorepermissive"Always"levelisrequested.if(floor(NSFoundationVersionNumber)>NSFoundationVersionNumber_iOS_7_1&&[CLLocationManagerauthorizationStatus]==kCLAuthorizationStatusNotDetermined){BOOLhasAlwaysKey=[[NSBundlemainBundle]objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"]!=nil;BOOLhasWhenInUseKey=[[NSBundlemainBundle]objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]!=nil;if(hasAlwaysKey){[self.m_locationManagerrequestAlwaysAuthorization];}elseif(hasWhenInUseKey){[self.m_locationManagerrequestWhenInUseAuthorization];}else{//AtleastoneofthekeysNSLocationAlwaysUsageDescriptionorNSLocationWhenInUseUsageDescriptionMUSTbepresentintheInfo.plistfiletouselocationservicesoniOS8+.NSAssert(hasAlwaysKey||hasWhenInUseKey,@"TouselocationservicesiniOS8+,yourInfo.plistmustprovideavalueforeitherNSLocationWhenInUseUsageDescriptionorNSLocationAlwaysUsageDescription.");}}#endif/*__IPHONE_OS_VERSION_MAX_ALLOWED>__IPHONE_7_1*/[self.m_locationManagerstartUpdatingLocation];

上述代码添加在

[self.m_locationManagerstartUpdatingLocation];


之前,

除了上述代码,还需要在info.plist中添加:

<key>NSLocationWhenInUseUsageDescription</key>

<string>这里是授权弹出框描述文字</string>

<key>NSLocationAlwaysUsageDescription</key>

<string>这里是授权弹出框描述文字</string>