我正在按照'iOS Apprentice'中的教程编写一个快速的应用程序,在这一步,我想使用场景中的getButton来显示访问GPS的授权警报,但它不起作用。我查了一下代码并修改info.plist(添加了NSLocationWhenInUsageDescription)但仍无效。
import UIKit
import CoreLocation
class CurrentLocationViewController: UIViewController,CLLocationManagerDelegate {
let locationManager = CLLocationManager()
@IBOutlet weak var messageLabel:UILabel!
@IBOutlet weak var latitudeLabel:UILabel!
@IBOutlet weak var longitudeLabel:UILabel!
@IBOutlet weak var addressLabel:UILabel!
@IBOutlet weak var tagButton:UIButton!
@IBOutlet weak var getButton:UIButton!
@IBAction func getLocation() {
let authStatus:CLAuthorizationStatus = CLLocationManager.authorizationStatus()
if authStatus == .NotDetermined {
locationManager.requestWhenInUseAuthorization()
return
}
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locationManager.startUpdatingLocation()
}
// MARK: - CLLocationManagerDelegate
func locationManager(manager:CLLocationManager!,didFailWithError error:NSError!) {
print("didFailWithError \(error)")
}
func locationManager(manager:CLLocationManager!,didUpdateLocations locations:[AnyObject]!) {
let newLocation = locations.last as! CLLocation
print("didUpdateLocations \(newLocation)")
}