【发布时间】:2023-12-02 16:08:02
【问题描述】:
我之前与 CLLocationManager 合作过很多次,并且我还有其他几个项目可以很好地使用 EXACT SAME 代码...必要的属性也在 info.Plist 中。
我在模拟器和设备上都试过了,在我的其他项目中都运行良好。如果有人能够提供帮助,那就太好了,因为我快要失去理智了。谢谢!
必需的 plist 属性
<key>NSLocationAlwaysUsageDescription </key>
<string>Can we use your location? </string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Can we use your location?</string>
主VC中的代码
import UIKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
let clientKey = ""
let clientSecred = ""
let pushSecret = ""
let fourSquareVersion = ""
let section = ""
var latLong = ""
var currentLat : Double?
var currentLong : Double?
var locationManager : CLLocationManager!
override func viewDidLoad() {
super.viewDidLoad()
locationManager = CLLocationManager()
locationManager.requestAlwaysAuthorization()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.distanceFilter = kCLDistanceFilterNone
locationManager.delegate = self
locationManager.startUpdatingLocation()
}
func locationManager(manager: CLLocationManager, didUpdateToLocation newLocation: CLLocation, fromLocation oldLocation: CLLocation) {
if let currentLocation : CLLocation = newLocation {
currentLat = currentLocation.coordinate.latitude
currentLong = currentLocation.coordinate.longitude
print(currentLat)
print(currentLong)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
【问题讨论】:
标签: swift2 ios9 cllocationmanager