gpt4 book ai didi

ios - xcode 8 swift 3 latlong 在模拟器上工作但不在设备中工作

转载 作者:行者123 更新时间:2023-11-30 12:58:57 25 4
gpt4 key购买 nike

我有这个代码来获取位置经纬度

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com