LocationManager的ios 不走代理方法法不走可能是什么原因

搜索结果部分由关于ios8以后CLLocationManager不定位不执行协议方法。zu
_instance.locationManager = [[CLLocationManager alloc] init];//创建位置管理器
_instance.locationManager.delegate=_
_instance.locationManager.desiredAccuracy=kCLLocationAccuracyB
_instance.locationManager.distanceFilter=100.0f;
_instance.updating=NO;
//定位服务是否可用
BOOL enable=[CLLocationManager locationServicesEnabled];
if ([[[UIDevicecurrentDevice]systemVersion]doubleValue] & 8.0)
//是否具有定位权限
int status=[CLLocationManager authorizationStatus];
if(!enable || status&3){
//请求权限
[_instance.locationManager requestWhenInUseAuthorization];
//_instance.locationManager requestAlwaysAuthorization];// 前后台同时定位
应该在[locationManager startUpdatingLocation];这一句上面加上判断。
if ([[[UIDevicecurrentDevice]systemVersion]doubleValue]
[locationManager requestWhenInUseAuthorization];//前台定位
[locationManager requestAlwaysAuthorization];//
前后台同时定位
加上以后打开info.plist。
在最后一行添加NSLocationWhenInUseUsageDescription或者NSLocationAlwaysUsageDescription(根据上面写得前台定位还是前后台定位),键值对可以为空。
注意IOS9以后定位跟contacts一样都需要判断是否进行隐私授权的,方法跟contacts一样,借鉴contacts一篇。定位也有方法authorizationStatus
没有更多推荐了,
加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!1 。不走代理方法
IOS8以后,需要在info.plist文件里面加NSLocationWhenInUseDescription或NSLocationAlwaysUsageDescription。后面的描述随便加。IOS以后需要到CLLocationManager得代理- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status来判断用户定位的状态。如果状态为kCLAuthorizationStatusNotDetermined,就调用plist里面的相对应的方法(如果你的plist写的是NSLocationWhenInUseDescription就调用[_locationManager requestWhenInUseAuthorization],如果是NSLocationAlwaysUsageDescription就调用[_locationManager requestAlwaysAuthorization])。定位就用- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations就好了。
2真机测试无法进行发出警告
&No provisioned iOS devices are available with a compatible iOS version. Connect an iOS device with a recent enough version of iOS to run your application or choose an iOS simulator as the destination.
点击你的项目》》TARGETS》》iOS Deployment Target》》修改为低于你设备的版本号。
阅读(...) 评论()主题 : 关于高德地图AMapLocationManager代理方法不能调用问题
级别: 新手上路
UID: 579031
可可豆: 194 CB
威望: 157 点
在线时间: 80(时)
发自: Web Page
来源于&&分类
关于高德地图AMapLocationManager代理方法不能调用问题&&&
求解!- (void)amapLocationManager:(AMapLocationManager *)manager didUpdateLocation:(CLLocation *)location{&&&&//定位结果&&&&NSLog(@&location:{lat:%f; lon:%f; accuracy:%f}&, location.coordinate.latitude, location.coordinate.longitude, location.horizontalAccuracy);}这个方法不能调用是什么问题,代理方法和Key都已经设置是不是我有什么遗漏的地方求告知
级别: 骑士
UID: 536225
可可豆: 1822 CB
威望: 1331 点
在线时间: 657(时)
发自: Web Page
代理设置了吗,建议去官网上认真仔细的查看🌰
级别: 新手上路
UID: 579031
可可豆: 194 CB
威望: 157 点
在线时间: 80(时)
发自: Web Page
回 1楼(gxp) 的帖子
代理是没有问题的,地图的定位都没有影响,但是就是不能调用这个方法
级别: 骑士
UID: 405098
可可豆: 1642 CB
威望: 1251 点
在线时间: 514(时)
发自: Web Page
持续定位和单次定会有有冲突,如果打开了持续定位,单次定位就不会执行,这个方法有个返回时是BOOL类型的,如果返回值是NO的话,说明你打开了持续定位,该代理方法就不会执行。
级别: 新手上路
UID: 579031
可可豆: 194 CB
威望: 157 点
在线时间: 80(时)
发自: Web Page
回 3楼(孟祥) 的帖子
已解决!加载locationManager必须放在viewDidLoad中,如果使用懒加载方式加载locationManager,他是不会走AMapLocationManagerDelegate代理方法的!切记切记!- (void)viewDidLoad {&&&&[super viewDidLoad];&&&&&&&&//配置Key&&&&[AMapServices sharedServices].apiKey = @&你的Key&;//&&&&[self locateAction];&&&&[AppUntils saveUUIDToKeyChain];&&&&//将地图加入视图&&&&[self.view addSubview:self.mapView];&&&&[self.view addSubview:self.btn];&&&&self.locationManager = [[AMapLocationManager alloc] init];&&&&self.locationManager.delegate =&&&&[self.locationManager setLocationTimeout: 2.0];&&&&&&&&//设置逆地理超时时间&&&&[self.locationManager setReGeocodeTimeout: 2.0];&&&&_locationManager.distanceFilter = 100.0;&&&&_locationManager.desiredAccuracy = kCLLocationAccuracyB&& //持续定位&&&&[self.locationManager startUpdatingLocation];而且必须开启持续定位
级别: 版主
UID: 533249
可可豆: 3474 CB
威望: 2352 点
在线时间: 541(时)
发自: Web Page
lazy var locationManager = AMapLocationManager()&&我用的就是懒加载&&是可以的,应该是你调用出问题了
https://github.com/YTiOSerhttps://www.jianshu.com/u/562ebc94345f
级别: 新手上路
UID: 579031
可可豆: 194 CB
威望: 157 点
在线时间: 80(时)
发自: Web Page
回 5楼(yangTaoCocos) 的帖子
请您将代码贴出来吧,让大家学一下,毕竟像我这样接触地图比较少的人还是比较多的 &&&&
级别: 版主
UID: 533249
可可豆: 3474 CB
威望: 2352 点
在线时间: 541(时)
发自: Web Page
回 6楼() 的帖子
lazy var locationManager = AMapLocationManager()&&&&&&&&lazy var mapView: MAMapView = {&&&&&&&&var mapview = MAMapView()&&&&&&&&mapview = MAMapView.init(frame: self.view.bounds)&&&&&&&&mapview.delegate = self&&&&&&&&mapview.logoCenter = CGPoint.init(x: mapview.bounds.size.width * 0.9, y: mapview.bounds.size.height * 0.9)&&&&&&&&mapview.showsScale = false //隐藏比例尺&&&&&&&&mapview.setZoomLevel(13.1, animated: true)&&&&&&&&mapview.showsUserLocation = true&&&&&&&&mapview.userTrackingMode = .FollowWithHeading&&&&&&&&&&&&&&&&return mapview&&&&}()&&&&&&&&override func viewDidLoad() {&&&&&&&&&&&&&&&&self.view.addSubview(mapView)&&&&&&&&&&&&&&&&configLocationManager()&&&&&&&&&&&&} // 配置定位管理&&&&func configLocationManager() {&&&&&&&&&&&&&&&&if CLLocationManager.locationServicesEnabled() == false{&&&&&&&&&&&&self.showToast(&定位服务当前可能尚未打开,请到设置中打开该应用的定位权限!&)&&&&&&&&}&&&&&&&&&&&&&&&&locationManager.delegate = self&&&&&&&&//设置期望定位精度&&&&&&&&locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters//定位精度&&&&&&&&locationManager.pausesLocationUpdatesAutomatically = false&&&&&&&&locationManager.distanceFilter = 10 //定位的最小更新距离&&&&&&&&locationManager.locationTimeout = defaultLocationTimeout&&&&&&&&locationManager.reGeocodeTimeout = defaultReGeocodeTimeout&&&&&&&&// 启动跟踪定位&&&&&&&&locationManager.startUpdatingLocation()&&&&}
https://github.com/YTiOSerhttps://www.jianshu.com/u/562ebc94345f
级别: 版主
UID: 533249
可可豆: 3474 CB
威望: 2352 点
在线时间: 541(时)
发自: Web Page
回 6楼() 的帖子
希望对你有所帮助,互相提高
https://github.com/YTiOSerhttps://www.jianshu.com/u/562ebc94345f
级别: 新手上路
UID: 579031
可可豆: 194 CB
威望: 157 点
在线时间: 80(时)
发自: Web Page
回 8楼(yangTaoCocos) 的帖子
厉害啦,swift还没搞,做完这个项目之后有时间学习一下。 &&&&
关注本帖(如果有新回复会站内信通知您)
发帖、回帖都会得到可观的积分奖励。
按"Ctrl+Enter"直接提交
关注CocoaChina
关注微信 每日推荐
扫一扫 关注CVP公众号
扫一扫 浏览移动版swift 写 CLLocationManager 为什么就不调用代理_百度知道
swift 写 CLLocationManager 为什么就不调用代理
我有更好的答案
iOS8以前使用CoreLocation定位1、首先定义一个全局的变量用来记录CLLocationManager对象,引入CoreLocation.framework使用#import &CoreLocation/CoreLocation.h&1
@property (nonatomic, strong) CLLocationManager
*locationM
2、初始化CLLocationManager并开始定位
self.locationManager = [[CLLocationManager alloc]init];_locationManager.delegate =_locationManager.desiredAccuracy = kCLLocationAccuracyB_locationManager.distanceFilter = 10;[_locationManager startUpdatingLocation];
3、实现CLLocationManagerDelegate的代理方法(1)获取到位置数据,返回的是一个CLLocation的数组,一般使用其中的一个
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
CLLocation *currLocation = [locations lastObject];
NSLog(@&经度=%f 纬度=%f 高度=%f&, currLocation.coordinate.latitude, currLocation.coordinate.longitude, currLocation.altitude);}
(2)获取用户位置数据失败的回调方法,在此通知用户- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
if ([error code] == kCLErrorDenied)
//访问被拒绝
if ([error code] == kCLErrorLocationUnknown) {
//无法获取位置信息
4、在viewWillDisappear关闭定位
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[_locationManager stopUpdatingLocation];}
iOS8中使用CoreLocation定位1、在使用CoreLocation前需要调用如下函数【iOS8专用】:iOS8对定位进行了一些修改,其中包括定位授权的方法,CLLocationManager增加了下面的两个方法:(1)始终允许访问位置信息- (void)requestAlwaysA(2)使用应用程序期间允许访问位置数据- (void)requestWhenInUseA示例如下:
self.locationManager = [[CLLocationManager alloc]init];_locationManager.delegate =_locationManager.desiredAccuracy = kCLLocationAccuracyB_locationManager.distanceFilter = 10;[_locationManager requestAlwaysAuthorization];//添加这句[_locationManager startUpdatingLocation];
2、在Info.plist文件中添加如下配置:(1)NSLocationAlwaysUsageDescription(2)NSLocationWhenInUseUsageDescription
采纳率:73%
来自团队:
为您推荐:
其他类似问题
swift的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。

我要回帖

更多关于 textview代理方法不走 的文章

 

随机推荐