有人尝试以编程方式在地图上模拟 iOS UI 测试的位置(不使用编辑方案> 允许位置模拟)吗?
问问题
197 次
1 回答
0
创建协议和模拟位置管理器
import CoreLocation
protocol LocationManager: class {
var location: CLLocation? { get }
}
final class MockCLLocationManager: LocationManager {
var location: CLLocation? {
return CLLocation(latitude: CLLocationDegrees(exactly: 52.51657052665494)!,
longitude: CLLocationDegrees(exactly: 13.381044881575008)!)
}
}
extension CLLocationManager: LocationManager { }
然后在您的地图视图控制器中:
let locationManager: LocationManager = MockCLLocationManager()
我无法让地图视图以这种方式显示蓝色用户位置指示器。
于 2019-04-09T07:24:58.380 回答