|
|
|
@ -27,7 +27,6 @@ public class LocationService: NSObject { |
|
|
|
super.init() |
|
|
|
setupLocationManager() |
|
|
|
} |
|
|
|
|
|
|
|
private func setupLocationManager() { |
|
|
|
DispatchQueue.main.async { [weak self] in |
|
|
|
self?.locationManager = CLLocationManager() |
|
|
|
@ -35,15 +34,26 @@ public class LocationService: NSObject { |
|
|
|
self?.locationManager?.desiredAccuracy = kCLLocationAccuracyBest |
|
|
|
self?.locationManager?.distanceFilter = 10 |
|
|
|
|
|
|
|
// 初始化时获取当前状态 |
|
|
|
self?.authorizationStatus = CLLocationManager.authorizationStatus() |
|
|
|
self?.isLocationServicesEnabled = CLLocationManager.locationServicesEnabled() |
|
|
|
|
|
|
|
print("[LocationService] LocationManager 初始化完成") |
|
|
|
print("[LocationService] 初始权限状态: \(self?.authorizationStatus.rawValue ?? -1)") |
|
|
|
print("[LocationService] 位置服务启用: \(self?.isLocationServicesEnabled ?? false)") |
|
|
|
// 不需要手动获取状态,delegate 方法会自动被调用 |
|
|
|
print("[LocationService] LocationManager 初始化完成,等待权限状态回调") |
|
|
|
} |
|
|
|
} |
|
|
|
// private func setupLocationManager() { |
|
|
|
// DispatchQueue.main.async { [weak self] in |
|
|
|
// self?.locationManager = CLLocationManager() |
|
|
|
// self?.locationManager?.delegate = self |
|
|
|
// self?.locationManager?.desiredAccuracy = kCLLocationAccuracyBest |
|
|
|
// self?.locationManager?.distanceFilter = 10 |
|
|
|
|
|
|
|
// // 初始化时获取当前状态 |
|
|
|
// self?.authorizationStatus = CLLocationManager.authorizationStatus() |
|
|
|
// self?.isLocationServicesEnabled = CLLocationManager.locationServicesEnabled() |
|
|
|
|
|
|
|
// print("[LocationService] LocationManager 初始化完成") |
|
|
|
// print("[LocationService] 初始权限状态: \(self?.authorizationStatus.rawValue ?? -1)") |
|
|
|
// print("[LocationService] 位置服务启用: \(self?.isLocationServicesEnabled ?? false)") |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
/// 获取当前位置 - 主要接口 |
|
|
|
public func getCurrentLocation(completion: @escaping (Result<[String: Any], Error>) -> Void) { |
|
|
|
|