Una*_*dra 9 core-location mapkit ios swift
我的Swift-iOS应用程序旨在显示用户在地图上的位置.但是,XCode调试控制台告诉我,我需要请求权限才能显示用户的位置.我想,我这样做,但对话永远不会出现.
这是错误消息,在我调用的ViewController下面 CLLocationManager::requestWhenInUseAuthorization()
错误:
2014-06-30 21:25:13.927 RowingTracker2 [17642:1608253]尝试在不提示位置授权的情况下启动MapKit位置更新.必须首先调用 - [CLLocationManager requestWhenInUseAuthorization]或 - [CLLocationManager requestAlwaysAuthorization].
视图控制器:
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, MKMapViewDelegate {
@IBOutlet var mapview: MKMapView = nil
var locationmgr : CLLocationManager!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
locationmgr = CLLocationManager()
locationmgr.requestWhenInUseAuthorization()
mapview.showsUserLocation = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Run Code Online (Sandbox Code Playgroud)
如何申请授权使用该位置?你可以在这里找到完整的项目.(提交)
甚至使视图控制器继承CLLocationManagerDelegate并设置委托self指示这里没有帮助.
您需要使用requestWhenInUseAuthorization并且还需要在yourapp-Info.plist上创建一个名为NSLocationWhenInUseUsageDescription的值
| 归档时间: |
|
| 查看次数: |
17860 次 |
| 最近记录: |