위치 데이터를 사용하여 간단한 iOS 앱을 만들고 싶습니다. 불행히도, 장치 및 시뮬레이터에서 테스트하는 동안 시뮬레이터에서 "현재 위치"디버그 코드를 입력하더라도 'nil'을 수신합니다. 스위프트 3에서 CoreLocation을 처음 사용하기 때문에 이전에 사용했던 것과 같은 방식을 사용했습니다.위치 신속 문제 3
import UIKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
@IBOutlet weak var latitudeLabel: UILabel!
@IBOutlet weak var longitudeLabel: UILabel!
var locationManager:CLLocationManager?
var currentLocation:CLLocation?
override func viewDidLoad() {
super.viewDidLoad()
let locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.startUpdatingLocation()
updateLabels()
// Do any additional setup after loading the view, typically from a nib.
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
self.currentLocation = locations[0]
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print(error)
}
func updateLabels() {
latitudeLabel.text = String(describing: currentLocation?.coordinate.latitude)
longitudeLabel.text = String(describing: currentLocation?.coordinate.longitude)
print(currentLocation)
}
}
물론 저는 Info.plist에 필요한 개인 키를 모두 작성했습니다.
currentLocation을 인쇄하려고 할 때 나는 nil을받습니다. 마지막 출시와 함께 경고가 표시되는 것보다 그러한 문제가 발견되었지만 즉시 사라졌습니다.
당신은 "나는 '전무'를받을"이란 무엇을 의미합니까? 문제를 분명히하십시오. 응답을 위해 – rmaddy
주셔서 감사합니다. 편집 된 설명. –