Files
suixinkan_uikit/suixinkan/Features/Location/LocationProviding.swift

62 lines
1.7 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// LocationProviding.swift
// suixinkan
//
import CoreLocation
import Foundation
///
struct HomeLocationSnapshot: Sendable, Equatable {
let latitude: Double
let longitude: Double
let address: String
}
/// 便 ViewModel mock
protocol LocationProviding: Sendable {
///
func requestSnapshot() async throws -> HomeLocationSnapshot
///
func requestCoordinate(desiredAccuracy: CLLocationAccuracy) async throws -> CLLocationCoordinate2D
///
func reverseGeocode(latitude: Double, longitude: Double) async -> String
}
extension LocationProviding {
/// 使
func requestCoordinate() async throws -> CLLocationCoordinate2D {
try await requestCoordinate(desiredAccuracy: kCLLocationAccuracyBest)
}
}
///
enum LocationProviderError: LocalizedError, Equatable {
case privacyNotAccepted
case permissionDenied
case locationFailed
var errorDescription: String? {
switch self {
case .privacyNotAccepted:
"请先阅读并同意隐私政策"
case .permissionDenied:
"需要定位权限才能使用此功能"
case .locationFailed:
"定位失败,请稍后重试"
}
}
}
///
enum OrderLocationError: LocalizedError {
case permissionDenied
var errorDescription: String? {
switch self {
case .permissionDenied:
"缺少定位权限,功能无法进行"
}
}
}