-2
앱을 처음 열 때 사용자 위치를 한 번만 가져 오려고합니다. (다른 오프닝에 대해 알고 싶지 않음)requestLocation을 사용하여 한 번만 사용자 위치를 요청하십시오.
나는 유저의 동의를 원하지 않는다.
아래 코드를 사용하고 있는데 위치를 알려주지 않았으므로 다음과 같은 오류가 표시됩니다. 작업을 완료 할 수 없습니다. (kCLErrorDomain 오류 0)
PS : 나는 실제 장치
코드와 함께 노력하고 시뮬레이터를 사용하고 있지 않다 :
import CoreLocation
import UIKit
class ViewController: UIViewController, CLLocationManagerDelegate {
let manager = CLLocationManager()
override func viewDidLoad() {
manager.delegate = self
manager.requestLocation()
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = locations.first {
print("Found user's location: \(location)")
}
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print("Failed to find user's location: \(error.localizedDescription)")
}
}
당신은 단지 위치를 요청 시작할 수없는 경우 앱 실행에 관한 정보. 위치 서비스에 대한 사용자 권한 부여 코드는 어디에 있습니까? – matt