我有这段代码来获取位置latlong
import Foundation
import CoreLocation
class Utilities{
static let locationManager = CLLocationManager()
static func InitLocator(Delegate:CLLocationManagerDelegate){
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.delegate = Delegate
locationManager.requestAlwaysAuthorization()
locationManager.distanceFilter = kCLDistanceFilterNone
locationManager.startUpdatingLocation()
}
static func GetLatLong() -> [String]{
var arrLatLong:[String] = []
if let latitude = locationManager.location?.coordinate.latitude{
arrLatLong.append(String(latitude))
}else{
arrLatLong.append("")
}
if let longitude = locationManager.location?.coordinate.longitude{
arrLatLong.append(String(longitude))
}else{
arrLatLong.append("")
}
return arrLatLong
}
}
当我在模拟器中测试或运行它时,此方法有效,但当我在实际设备中对其进行测试时,则为空白值。我使用Xcode 8 swift,设备是Iphone 6s IOS 9.3.1
最佳答案
试试看
添加locationManager.requestWhenInUseAuthorization()
和info.plist
关于ios - xcode 8 swift 3 latlong在模拟器上工作,但不在设备上,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40070515/