没有调用更新到位置

时间:2016-04-14 04:13:48

标签: swift core-location cllocationmanager

我刚开始使用地图和地点。我已将所需的代码添加到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 ")



    }

}

2 个答案:

答案 0 :(得分:0)

仅在plist

中添加以下内容
<key>NSLocationWhenInUseUsageDescription</key>
<string>Can we use your location?</string>

答案 1 :(得分:0)

亲爱的朋友,如果你在模拟器中测试的话。运行您的应用程序并选择模拟器并从上部选择调试选项卡,然后在硬件中选择位置和位置选择Apple而不是无 调试 - &GT;当前位置 - &GT;苹果

它会调用你的方法。但它会显示苹果作为一个位置,但如果你想要正确的位置,你必须登录iPhone enter image description here