Agontuk / react-native-geolocation-service

React native geolocation service for iOS and android
https://www.npmjs.com/package/react-native-geolocation-service
MIT License
1.6k stars 290 forks source link

iOS Crash in getCurrentPosition - Unexpectedly found nil while unwrapping an Optional value #369

Closed cristianoccazinsp closed 1 year ago

cristianoccazinsp commented 1 year ago

Environment

System:
    OS: macOS 12.4
    CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
    Memory: 380.82 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 14.17.6 - /usr/local/bin/node
    Yarn: 1.22.5 - /usr/local/bin/yarn
    npm: 8.9.0 - /usr/local/bin/npm
    Watchman: 2021.06.07.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.11.2 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
    Android SDK: Not Found
  IDEs:
    Android Studio: 2021.1 AI-211.7628.21.2111.8309675
    Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.14.1 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2 
    react-native: 0.67.4 => 0.67.4 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Platforms

iOS

Versions

Please add the used versions/branches

Description

Arbitrary crash in production from swift code.

Reproducible Demo

Regular use as documented:

Geolocation.getCurrentPosition(cb, {
 accuracy: {
    ios: 'best',
    android: 'high',
  },
  showLocationDialog: true,
  timeout: 30000,
  maximumAge: 0,
});

Crash log:

Role:               Foreground
OS Version:         iOS 12.5.5
Exception Type:     EXC_BREAKPOINT 
Exception Subtype:  KERN_INVALID_ADDRESS

EXC_BREAKPOINT: 

0  zinspector3       Swift runtime failure: Unexpectedly found nil while unwrapping an Optional value (LocationProvider.swift:41:81)
1  zinspector3       RNFusedLocation.getCurrentPosition(_:successCallback:errorCallback:) (RNFusedLocation.swift:57:22)
2  zinspector3       @objc RNFusedLocation.getCurrentPosition(_:successCallback:errorCallback:) (<compiler-generated>)
3  CoreFoundation    ___invoking___
4  CoreFoundation    -[NSInvocation invoke]
5  CoreFoundation    -[NSInvocation invokeWithTarget:]
6  zinspector3       -[RCTModuleMethod invokeWithBridge:module:arguments:] (RCTModuleMethod.mm:584:3)

Expected Results

No crash

@Agontuk any ideas? We've got a user that keeps getting this every time location access is attempted. Any nil checks missing?

cristianoccazinsp commented 1 year ago

Probably this line here: https://github.com/Agontuk/react-native-geolocation-service/blob/master/ios/LocationProvider.swift#L41

Should be using safe unwrapping (e.g., use a non-null local variable).

Screen Shot 2022-08-12 at 22 06 00
cristianoccazinsp commented 1 year ago

PR that should prevent the issue: https://github.com/Agontuk/react-native-geolocation-service/pull/370

cristianoccazinsp commented 1 year ago

@Agontuk any updates? We need this asap as we see many crashes due to this.

cristianoccazinsp commented 1 year ago

@Agontuk can we close this and do a new release with the merged PR?

Agontuk commented 1 year ago

new version released, sorry for the delay