3
我在使用CLLocationDelegate获取位置时遇到问题。 我创建了UIView的新子类,并且运行良好,但是当我创建NSObject的子类时,CLLocationDelegate没有被调用。我可以找到问题所在。 这里是我的代码:Swift,NSObject中的CLLocationManagerDelegate不起作用
import UIKit
import CoreLocation
class LocationData: NSObject, CLLocationManagerDelegate {
var locationManager : CLLocationManager = CLLocationManager()
override init() {
super.init()
if self.locationManager.respondsToSelector(Selector("requestAlwaysAuthorization")) {
self.locationManager.requestWhenInUseAuthorization()
}
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.distanceFilter = 50
self.locationManager.startUpdatingLocation()
println("init LocationData")
}
func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
println(error.description)
}
func locationManager(manager: CLLocationManager!, didUpdateToLocation newLocation: CLLocation!, fromLocation oldLocation: CLLocation!) {
println("updated")
}
}
谢谢!
你看过http://stackoverflow.com/questions/24062509/location-services-not-working-in-ios-8? – Anna 2015-03-19 13:00:19