iOS 8.0 CLLocationManager 定位 不响应
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>
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。