2017-05-24 1 views
0

시작시 즉시 사용자 위치를 얻으려고 시도하고이를 수행하기 위해 AppDelegate의 함수에서 업데이트 될 전역 변수 userLocation을 구현했습니다. 그래서 같은 위치 관리자를 구현 한 :AppDelegate 확장명이 호출되지 않음

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
    // Override point for customization after application launch. 
    var locationManager = CLLocationManager() 
    locationManager.delegate = self 
    locationManager.requestWhenInUseAuthorization() 
    if CLLocationManager.locationServicesEnabled(){ 
     locationManager.desiredAccuracy = kCLLocationAccuracyBest 
     locationManager.requestLocation() 
    } 
    return true 
} 

및 확장 :

extension AppDelegate: CLLocationManagerDelegate { 
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { 
     usersLocation = locations.last! 
    } 
    func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { 
     print(error) 
    } 
} 

userLocation 업데이트 결코 극복하고, 나는 userLocation = locations.last! 라인에 브레이크 포인트를 배치하고 그 도달하지 않았다. 어떤 조언

답변

1

에 대한

덕분에 난 당신이 너무 locationManager 변수를 유지한다고 생각합니다.

var locationManager: CLLocationManager! 

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
    // Override point for customization after application launch. 
    locationManager = CLLocationManager() 
    locationManager.delegate = self 
    locationManager.requestWhenInUseAuthorization() 
    if CLLocationManager.locationServicesEnabled(){ 
     locationManager.desiredAccuracy = kCLLocationAccuracyBest 
     locationManager.requestLocation() 
    } 
    return true 
} 
+0

감사합니다. 작동이 끝났지 만 여전히 내 요구에 충분히 빠르게 작동하지 않아서 사용자 상호 작용 전에로드 애니메이션을 추가 할 것입니다. –

관련 문제