iOS Swift: запрос местоположения пользователя

Я новичок в iOS Swift, пишу код iOS Swift и использую UIWebView для загрузки своей веб-страницы.

И моя веб-страница попросит пользователя указать местоположение пользователя .

Я хотел бы сделать подобное поведение в коде iOS Swift (всплывающее диалоговое окно и сказать что-то вроде «TestApp хотел бы получить доступ к вашему местоположению. Вы согласны?»)

Я работаю на симуляторе и я потерпел неудачу при использовании CLLocationManager

Вот мой код Swift

import UIKit
import CoreLocation

class ViewController: UIViewController, CLLocationManagerDelegate {
@IBOutlet weak var customWebView: UIWebView!


override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    if let url = NSURL(string: "http://ctrlq.org/maps/where/") {
        let request = NSURLRequest(URL: url)
        customWebView.loadRequest(request)

        let locationManager = CLLocationManager()
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.requestAlwaysAuthorization()
        locationManager.startUpdatingLocation()

    }
}

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

}

Кто-нибудь знает, как запросить местоположение?

Заранее спасибо.

Эрик

8
задан Eric Tseng 3 February 2015 в 04:49
поделиться