【发布时间】:2016-02-06 16:10:46
【问题描述】:
我有一个具有这些功能的视图控制器:
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]){
print("loc")
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError){
if(error.code == CLError.Denied.rawValue){
print("error")
}
}
是这个类的直接子类:
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
}
}
}
然后我有这门课
class CoreLocationController : NSObject {
func requestLocationUpdate(delegate : CLLocationManagerDelegate){
let locationManager = CLLocationManager()
locationManager.delegate = delegate
if #available(iOS 8.0, *) {
locationManager.requestWhenInUseAuthorization()
} else {
locationManager.startUpdatingLocation()
}
然后在 AppDelegate 我声明它像:
let coreLocationController = CoreLocationController()
但是当我从 UIViewLocationManager 的子 viewController 调用 requestLocationUpdate(self) 时,我没有收到任何更新。但是,如果我只是将所有方法复制粘贴到CoreLocationController 并在CoreLocationController init() 方法中执行locationManager.delegate = self,那么一切正常。
有什么想法吗?我真的很绝望,因为我已经尝试了很多方法,但仍然无法正常工作。
提前致谢
【问题讨论】:
标签: swift uiviewcontroller swift2 core-location