首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >应用程序不允许使用当前位置后的MKUserTrackingBarButtonItem旋转

应用程序不允许使用当前位置后的MKUserTrackingBarButtonItem旋转
EN

Stack Overflow用户
提问于 2014-06-27 16:30:12
回答 2查看 767关注 0票数 1

我在视图控制器的MKUserTrackingBarButtonItem中添加了一个viewDidLoad实例,如下所示:

代码语言:javascript
复制
MKUserTrackingBarButtonItem *userTrackingButton = [[MKUserTrackingBarButtonItem alloc] initWithMapView:self->mapView];
NSMutableArray *toolbarItems = [[NSMutableArray alloc] initWithArray:[mapToolBar items]];
[toolbarItems insertObject:userTrackingButton atIndex:0];
[mapToolBar setItems:toolbarItems];

“位置服务”在“设置”中打开,但对应用程序不打开。当点击MKUserTrackingBarButtonItem按钮时,模态对话框会询问用户是否允许应用程序使用当前位置。当选择“不允许”时,MKUserTrackingBarButtonItem会变成一个灰色虚线旋转图标,而原始的指南针图标不会恢复。

如何在地图应用程序中恢复按钮的状态?

所需的行为与地图应用程序中的行为相同。

  1. 确保在“设置”>“隐私”>“位置服务”中打开位置服务。
  2. 设置中的重置位置和隐私>一般>重置>重置位置和隐私。
  3. 启动地图应用程序。
  4. 点击左下角的指南针图标。
  5. 出现一个带有“地图”信息的对话框,希望使用您当前的位置。这时,指南针的图标变成了灰色的虚线旋转的图标。
  6. 选择“不允许”

恢复原来的指南针图标。

我正在iPhone上测试这个,而不是在模拟器上测试。当打开并允许应用程序使用当前位置时,上面的代码可以正常工作。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-06-27 17:13:46

实现CLLocationManagerDelegate方法:

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status

当CLAuthorizationStatus不是kCLAuthorizationStatusAuthorized时,可以将MKMapview的userTrackingMode属性更新为MKUserTrackingModeNone

票数 3
EN

Stack Overflow用户

发布于 2016-01-10 05:22:16

我在网上找不到很多帮助,但这个帖子帮了我很多忙。下面是对olicarbo所说的话的快速实施:

代码语言:javascript
复制
        func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
    mapView.showsUserLocation = (status == .AuthorizedAlways)

    //if location services are turned off for this app.
    if(status == CLAuthorizationStatus.AuthorizedAlways || status == CLAuthorizationStatus.AuthorizedWhenInUse){
        mapView.userTrackingMode = MKUserTrackingMode.None
    }
}

func mapView(mapView: MKMapView, didChangeUserTrackingMode mode: MKUserTrackingMode, animated: Bool) {
    if(CLLocationManager.locationServicesEnabled() == false || !(CLLocationManager.authorizationStatus() == CLAuthorizationStatus.AuthorizedWhenInUse || CLLocationManager.authorizationStatus() == CLAuthorizationStatus.AuthorizedAlways)){
        //location services are disabled or
        //user has not authorized permissions to use their location.

        mapView.userTrackingMode = MKUserTrackingMode.None
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24456694

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档