SiftScience / sift-react-native

React Native Wrapper for Sift iOS and Android SDKs
MIT License
1 stars 12 forks source link

`setSiftConfig` not properly setting `disallowCollectingLocationData` in Android #31

Closed chriszipdev closed 1 year ago

chriszipdev commented 1 year ago

When asking for precise location permission on Android, app would crash when user selects allow once or allow while using. (not an issue on IOS)

Current function

@ReactMethod
    fun setSiftConfig(accountId: String, beaconKey: String, disallowCollectingLocationData: Boolean,
                      serverUrlFormat: String) {
        siftConfig = if (TextUtils.isEmpty(serverUrlFormat)) {
          Sift.Config.Builder()
            .withAccountId(accountId)
            .withBeaconKey(beaconKey)
            .build()
        } else {
          Sift.Config.Builder()
            .withAccountId(accountId)
            .withBeaconKey(beaconKey)
            .withServerUrlFormat(serverUrlFormat)
            .build()
        }
        Sift.open(reactApplicationContext, siftConfig)
        Sift.collect()
    }

setSiftConfig seems to be missing the .withDisallowLocationCollection(disallowCollectingLocationData) chained method when calling .Builder

When I added that everything worked as expected

Suggested change

@ReactMethod
    fun setSiftConfig(accountId: String, beaconKey: String, disallowCollectingLocationData: Boolean,
                      serverUrlFormat: String) {
        siftConfig = if (TextUtils.isEmpty(serverUrlFormat)) {
          Sift.Config.Builder()
            .withAccountId(accountId)
            .withBeaconKey(beaconKey)
            .withDisallowLocationCollection(disallowCollectingLocationData)
            .build()
        } else {
          Sift.Config.Builder()
            .withAccountId(accountId)
            .withBeaconKey(beaconKey)
            .withServerUrlFormat(serverUrlFormat)
            .withDisallowLocationCollection(disallowCollectingLocationData)
            .build()
        }
        Sift.open(reactApplicationContext, siftConfig)
        Sift.collect()
    }
viaskal-sift commented 1 year ago

@chriszipdev thanks for bringing the issue, we will take a look at this, I will keep you posted

viaskal-sift commented 1 year ago

Hi @chriszipdev, the fix is released under this version - https://www.npmjs.com/package/sift-react-native/v/0.1.12, feel free to try that one

chriszipdev commented 1 year ago

Hi @viaskal-sift! Really appreciate you and your team getting to this so fast. I tested the package and it looks to have corrected the crash.

Thank you! 🙌