【发布时间】:2016-08-23 16:26:41
【问题描述】:
这是我的通用 ViewController 类,我研究了这个问题iOS app doesn't ask for location permission,我已经有了NSLocationAlwaysUsageDescription 和NSLocationWhenInUseUsageDescription
@IBOutlet weak var ownMapView: MKMapView!
let locationManager : CLLocationManager = CLLocationManager();
override func viewDidLoad() {
super.viewDidLoad();
self.locationManager.delegate = self;
self.locationManager.requestWhenInUseAuthorization();
self.locationManager.startUpdatingLocation();
}
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
guard status == .AuthorizedWhenInUse else
{
print("Location not using");
return;
}
print("Location using.");
ownMapView.showsUserLocation = true;
}
即使我添加了 NSLocationAlwaysUsageDescription 和 NSLocationWhenInUseUsageDescription 这对我也不起作用。它只打印“未使用的位置”
如何正确请求?
【问题讨论】:
-
第一次运行时,状态应该是“未确定”,你应该得到一个权限弹出窗口。你得到那个弹出窗口了吗?
-
第一次尝试我选择了不允许选项,然后程序从不询问位置允许请求。
-
我的意思是应用程序的第一次运行
-
尝试从设备/模拟器中删除应用并再次运行
-
我现在正在尝试删除并再次运行它