Login flow fixed
This commit is contained in:
46
pedi-foods/Sources/PediFoods/Services/LocationService.swift
Normal file
46
pedi-foods/Sources/PediFoods/Services/LocationService.swift
Normal file
@@ -0,0 +1,46 @@
|
||||
import Foundation
|
||||
|
||||
#if os(iOS)
|
||||
import CoreLocation
|
||||
#endif
|
||||
|
||||
final class LocationService: NSObject {
|
||||
#if os(iOS)
|
||||
private let manager = CLLocationManager()
|
||||
private var completion: ((Double, Double) -> Void)?
|
||||
#endif
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
#if os(iOS)
|
||||
manager.delegate = self
|
||||
manager.desiredAccuracy = kCLLocationAccuracyHundredMeters
|
||||
#endif
|
||||
}
|
||||
|
||||
func requestLocation(_ completion: @escaping (Double, Double) -> Void) {
|
||||
#if os(iOS)
|
||||
self.completion = completion
|
||||
manager.requestWhenInUseAuthorization()
|
||||
manager.requestLocation()
|
||||
#else
|
||||
// Android: implement later with platform-specific bridge
|
||||
_ = completion
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
extension LocationService: CLLocationManagerDelegate {
|
||||
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
|
||||
guard let location = locations.first else { return }
|
||||
completion?(location.coordinate.latitude, location.coordinate.longitude)
|
||||
completion = nil
|
||||
}
|
||||
|
||||
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
|
||||
// Silence for now; UI can handle missing location.
|
||||
completion = nil
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user