티스토리 뷰

info.plist에 

NSLocationWhenInUseUsageDescription

또는

NSLocationAlwaysUsageDescription

추가

GPS정보를 어플리케이션 사용중에만 사용한다면 NSLocationWhenInUseUsageDescription 에 안내 메세지를 입력한다.

GPS정보를 어플리케이션 항상 사용한다면 NSLocationAlwaysUsageDescription 에 안내 메세지를 입력한다.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import UIKit
import CoreLocation
 
class ViewController: UIViewController, CLLocationManagerDelegate {
 
    var locationManager:CLLocationManager!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        locationManager = CLLocationManager()
        locationManager.delegate = self
        locationManager.requestWhenInUseAuthorization() //권한 요청
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.startUpdatingLocation()
    }
 
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        //위치가 업데이트될때마다
        if let coor = manager.location?.coordinate{
            print("latitude" + String(coor.latitude) + "/ longitude" + String(coor.longitude))
        }
    }
}
cs


댓글
댓글쓰기 폼