I have a view controller which hase these functions:
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]){
print("loc")
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError){
if(error.code == CLError.Denied.rawValue){
print("error")
}
}
It is direct child of this class:
import UIKit
import CoreLocation
class UIViewLocationManager : UIViewController, CLLocationManagerDelegate{
func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
print(status.rawValue)
switch status {
case .NotDetermined:
break
case .AuthorizedWhenInUse:
if #available(iOS 9.0, *) {
manager.requestLocation()
} else {
manager.startUpdatingLocation()
}
break
case .AuthorizedAlways:
break
case .Denied:
break
default:
break
}
}
}
And then I have this class
class CoreLocationController : NSObject {
func requestLocationUpdate(delegate : CLLocationManagerDelegate){
let locationManager = CLLocationManager()
locationManager.delegate = delegate
if #available(iOS 8.0, *) {
locationManager.requestWhenInUseAuthorization()
} else {
locationManager.startUpdatingLocation()
}
then in AppDelegate I declare it like:
let coreLocationController = CoreLocationController()
But when I call requestLocationUpdate(self)
from viewController which is child of UIViewLocationManager
I dont receive any updates. However if I just copy-paste all methods to CoreLocationController
and I do locationManager.delegate = self
in CoreLocationController init()
method than everything works fine.
Any ideas? I am really desperate because I have already tried so much aproaches but still cant get this working.
Thanks in advance