2016-04-14 28 views
0

我剛開始使用地圖和位置。我已經添加了所需的代碼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 ") 



    } 

} 

回答

0

親愛的朋友,如果您在模擬器中測試。運行你的應用程序並選擇模擬器,然後從上面選擇調試選項卡,並在硬件中選擇位置和位置選擇Apple而不是無 調試 - >位置 - >蘋果

它會調用你的方法。但它會顯示蘋果作爲一個位置,但如果你想要正確的位置,你必須檢查iphone enter image description here

0

添加只在plist下面

<key>NSLocationWhenInUseUsageDescription</key> 
<string>Can we use your location?</string> 
+0

沒有輸出仍然@Sandeep庫馬爾 –

+0

你正在測試的設備上還是模擬器? –

+0

模擬器@Sandeep Kumar –