这是我的一般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
,这对我也不起作用。它仅打印"位置不使用"
我如何正确请求?
答案 0 :(得分:0)
让我们添加了NSLocationAlwaysUsageDescription&在plist中的NSLocationWhenInUseUsageDescription? 。添加这些,它将起作用。
答案 1 :(得分:0)
要正确理解这一点,请检查CLLAuthorizationStatus doc: https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/#//apple_ref/c/tdef/CLAuthorizationStatus
CLAuthorizationStatus有几个可能的值:
您正在检查"授权何时使用"状态,但您首先启动其状态为NotDetermined。
您可以进一步检查以下状态:
.jumbotron {
background-image:url('http://4.bp.blogspot.com/-CIy9X0Vwlko/VFvyStJbP_I/AAAAAAAACys/Ze7QVlcVmX0/s1600/HOPE%2BLogo%2Bcopy.jpg');
height: 600px;
background-repeat: no-repeat;
background-size: contain;
background-color: #FFFFFF;
position: relative;
}
.jumbotron .container {
position: relative;
top:100px;
}
.jumbotron h1 {
color: #fff;
font-size: 60px;
font-family: 'Love Ya Like A Sister', cursive;
font-weight: bold;
}
.jumbotron p {
font-size: 30px;
color: #A80000;
}