Skip to content

Commit bffb999

Browse files
cristianoccazinspAgontuk
authored andcommitted
iOS Crash fix due to race conditions
Make sure to keep a copy of the unwrapped variable in case it is nulled out in between.
1 parent c0639d0 commit bffb999

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

ios/LocationProvider.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class LocationProvider: NSObject {
3737
}
3838

3939
func getCurrentLocation(_ options: LocationOptions) -> Void {
40-
if locationManager.location != nil {
41-
let elapsedTime = (Date().timeIntervalSince1970 - locationManager.location!.timestamp.timeIntervalSince1970) * 1000
40+
if let location = locationManager.location {
41+
let elapsedTime = (Date().timeIntervalSince1970 - location.timestamp.timeIntervalSince1970) * 1000
4242

4343
#if DEBUG
4444
NSLog("RNLocation: elapsedTime=\(elapsedTime)ms, maxAge=\(options.maximumAge)ms")
@@ -48,7 +48,7 @@ class LocationProvider: NSObject {
4848
#if DEBUG
4949
NSLog("RNLocation: returning cached location")
5050
#endif
51-
delegate?.onLocationChange(self, location: locationManager.location!)
51+
delegate?.onLocationChange(self, location: location)
5252
return
5353
}
5454
}

0 commit comments

Comments
 (0)