在ios 10 swift 3模拟器

时间:2017-01-12 04:47:00

标签: swift3 ios10

永远不会调用CLLocationManager委托。这是我的代码:

  import UIKit
  import CoreLocation
  class LocationController: UITableViewController, CLLocationManagerDelegate {
  override func viewDidLoad() {
    super.viewDidLoad()
    if (CLLocationManager.locationServicesEnabled())
    {
        locationManager.delegate = self;
        locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
        // ask permission - NOT NECESSARY IF YOU ALREADY ADDED NSLocationAlwaysUsageDescription IT UP INFO.PLIST
        locationManager.requestAlwaysAuthorization()
        // when in use foreground
        locationManager.requestWhenInUseAuthorization()
        locationManager.startUpdatingLocation()
    }
    else{
        print("set up location access  in info.plist")
    }
   }

   private func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    print("locationmanager got called")
    let locValue:CLLocationCoordinate2D = manager.location!.coordinate
    print("locations = \(locValue.latitude) \(locValue.longitude)")
   }
  }

info.plist设置:

info.plist

我的模拟器设置:

simulator setting

1 个答案:

答案 0 :(得分:0)

您是否在开始申请后更改了位置?在菜单中:Debug / Location / ... 或者更改默认位置(在上次屏幕截图中)