2016-10-25 7 views
0

저는 신속한 신규 사용자이며 경도와 latitutde를 표시하는 기본 프로그램을 얻으려고합니다.신속한 ios10에서 위치 관리자가 업데이트되지 않습니다.

import UIKit 
import CoreLocation 

class ViewController: UIViewController, CLLocationManagerDelegate { 

@IBOutlet weak var latLabel: UILabel! 
@IBOutlet weak var longLabel: UILabel! 
@IBOutlet weak var addLabel: UILabel! 
var lm = CLLocationManager() 

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 
    lm = CLLocationManager() 
} 

@IBAction func getCurrentLocation(_ sender: AnyObject) { 
    lm.delegate = self 
    lm.desiredAccuracy = kCLLocationAccuracyBest 
    lm.startUpdatingLocation() 
    print("loc") 

} 

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { 
    print ("error") 
} 

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { 
    print ("location") 
    let length = locations.count 
    let curLoc = locations[length-0] 
    latLabel.text = String(curLoc.coordinate.latitude) 
    print ("loccation") 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 


} 

답변

1

검사가 한 번 다음과 같은보다 자세한 내용은 PLIST

Location : 
Key  : Privacy - Location Always Usage Description 
Value : $(PRODUCT_NAME) location use 

Key  : Privacy - Location When In Use Usage Description 
Value : $(PRODUCT_NAME) location use 

this

3

당신은 두 가지를 누락 참조 추가됩니다.

  1. 당신은 또는 requestWhenInUseAuthorization() requestAlwaysAuthorization를 사용 허가를 요청해야합니다. 당신이 viewdidlod에 위치 관리자를 할당 할 때

그래서 좋아하니이

locationManager = CLLocationManager() 
locationManager.delegate = self 
locationManager.desiredAccuracy = kCLLocationAccuracyBest 
locationManager.requestAlwaysAuthorization() 
당신은 @ Anbu.Karthik 등의 정보를 추가 할 필요가
  • 제안했다
      을 그의 대답에.

    사용 앱을 공개하지 않고 사용하는 경우에도 장치의 위치를 ​​사용하려면 애플 리케이션을위한 NSLocationAlwaysUsageDescription.

    사용 앱을 열고 사용중인 경우에만 장치의 위치를 ​​사용하려면 애플 리케이션을위한 NSLocationWhenInUseUsageDescription.

    enter image description here