ReviewOS

also looking at this

craft-native/craft

fix(ios): ask again when Core Location has no fix yet, rather than failing the caller

#264
Merged glennmichael123 wants to merge fix/ios-location-no-fix-yet into main
3 files +120 -7
packages/ios/templates/CraftApp.swiftmodified+15-1
Changes to packages/ios/templates/CraftApp.swift
@@ -4119,9 +4119,23 @@ struct CraftWebView: UIViewRepresentable {
41194119 }
41204120
41214121 func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
4122 let nativeError = error as NSError
4123 // kCLErrorLocationUnknown is Core Location saying it has no fix
4124 // *yet*, not that it failed. requestLocation gives up on it, so a
4125 // one-shot asks again shortly instead of failing a caller whose
4126 // fix was seconds off; its timeout still bounds the wait (#260).
4127 // Nor is it an error event: a watch keeps running through it.
4128 if nativeError.domain == kCLErrorDomain && nativeError.code == CLError.Code.locationUnknown.rawValue {
4129 if let waiting = singleLocationCallbackId {
4130 DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) { [weak self] in
4131 guard let self, self.singleLocationCallbackId == waiting else { return }
4132 self.locationManager?.requestLocation()
4133 }
4134 }
4135 return
4136 }
41224137 let callbackId = singleLocationCallbackId
41234138 finishSingleLocationRequest()
4124 let nativeError = error as NSError
41254139 let code = nativeError.domain == kCLErrorDomain && nativeError.code == CLError.Code.denied.rawValue
41264140 ? "PERMISSION_DENIED"
41274141 : "POSITION_UNAVAILABLE"