also looking at this
fix(ios): ask again when Core Location has no fix yet, rather than failing the caller
#264
3 files
+120
-7
| @@ -4119,9 +4119,23 @@ struct CraftWebView: UIViewRepresentable { | ||
| 4119 | 4119 | } |
| 4120 | 4120 | |
| 4121 | 4121 | 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 | } | |
| 4122 | 4137 | let callbackId = singleLocationCallbackId |
| 4123 | 4138 | finishSingleLocationRequest() |
| 4124 | let nativeError = error as NSError | |
| 4125 | 4139 | let code = nativeError.domain == kCLErrorDomain && nativeError.code == CLError.Code.denied.rawValue |
| 4126 | 4140 | ? "PERMISSION_DENIED" |
| 4127 | 4141 | : "POSITION_UNAVAILABLE" |