没有调用更新到位置
the did Update To location is not being called
我刚刚开始使用地图和位置。我已经将所需的代码添加到 info.plist 中(紧接在 <dict>
之后):
<key>NSLocationAlwaysUsageDescription</key>
<string>Can we use your location?</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Can we use your location?</string>
但是我无法调用该函数,因此我没有任何输出
import UIKit
import CoreLocation
class ViewController: UIViewController , CLLocationManagerDelegate {
var locationManeger = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManeger.delegate = self
locationManeger.requestWhenInUseAuthorization()
locationManeger.startUpdatingLocation()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func locationManager(manager: CLLocationManager, didUpdateToLocation newLocation: CLLocation, fromLocation oldLocation: CLLocation) {
print("got the location ")
}
}
仅在 plist 下方添加
<key>NSLocationWhenInUseUsageDescription</key>
<string>Can we use your location?</string>
亲爱的朋友,如果您正在模拟器中进行测试。 运行 您的应用程序和 select 模拟器和 select 从上方和在硬件中的调试选项卡 select 位置和位置 select Apple 而不是 None
调试->位置->Apple
它会调用您的方法。但它会将 apple 显示为位置,但如果您想要正确的位置,则必须签入 iphone
我刚刚开始使用地图和位置。我已经将所需的代码添加到 info.plist 中(紧接在 <dict>
之后):
<key>NSLocationAlwaysUsageDescription</key>
<string>Can we use your location?</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Can we use your location?</string>
但是我无法调用该函数,因此我没有任何输出
import UIKit
import CoreLocation
class ViewController: UIViewController , CLLocationManagerDelegate {
var locationManeger = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManeger.delegate = self
locationManeger.requestWhenInUseAuthorization()
locationManeger.startUpdatingLocation()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func locationManager(manager: CLLocationManager, didUpdateToLocation newLocation: CLLocation, fromLocation oldLocation: CLLocation) {
print("got the location ")
}
}
仅在 plist 下方添加
<key>NSLocationWhenInUseUsageDescription</key>
<string>Can we use your location?</string>
亲爱的朋友,如果您正在模拟器中进行测试。 运行 您的应用程序和 select 模拟器和 select 从上方和在硬件中的调试选项卡 select 位置和位置 select Apple 而不是 None 调试->位置->Apple
它会调用您的方法。但它会将 apple 显示为位置,但如果您想要正确的位置,则必须签入 iphone