【发布时间】:2016-05-23 07:13:43
【问题描述】:
在过去的 2 个小时里,我一直在尝试找出核心定位器无法找到我的设备位置的原因。
事实是:
- 它不适用于模拟器或我的 iPhone
- 我可以接受应用程序以访问我在应用程序中的位置,但之后没有任何反应
- 我正在使用 Swift 并使用 Xcode 6.4
- 我已将 NSLocationWhenInUseUsageDescription 和 NSLocationAlwaysUsageDescription 都输入到我的 info.plist
import UIKit
import MapKit
import CoreLocation
class satelliteViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
@IBOutlet weak var mapView: MKMapView!
@IBOutlet weak var mapTypeTitle: UIButton!
var locationManager: CLLocationManager?
override func viewDidLoad() {
super.viewDidLoad()
locationManager = CLLocationManager()
locationManager!.delegate = self
locationManager!.desiredAccuracy = kCLLocationAccuracyBest
locationManager!.requestWhenInUseAuthorization()
locationManager!.startUpdatingLocation()
}
@IBAction func changeMapType(sender: AnyObject) {
// Unimportant
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
【问题讨论】:
-
你实现了
didUpdateLocation等委托函数吗? -
我之前已经添加了 didUpdateLocation、didFailWithError 和 didChangeAuthorizationStatus 函数,但它似乎没有做任何事情
-
你能告诉我们这些函数的代码吗?
-
我搞定了,谢谢你的帮助 :)
标签: ios swift authorization core-location cllocationmanager