SudoPlz / sp-react-native-in-app-updates

An in-app updater for the native version of your react-native app.
MIT License
491 stars 66 forks source link

startUpdate error: Error: Update type unavailable, check checkNeedsUpdate.isImmediateUpdateAllowed or checkNeedsUpdate.isFlexibleUpdateAllowed first. #127

Open JameDodgers opened 1 year ago

JameDodgers commented 1 year ago

Hello, thank you for your work in this library.

I recently started to use it and I'm receiving this error in Sentry, which made me think if the code in docs and example project shouldn't be changed to something like that:

inAppUpdates.checkNeedsUpdate().then((result) => {
  if (result.shouldUpdate) {
    let updateOptions = {};
    if (Platform.OS === 'android') {
      if (result.isFlexibleUpdateAllowed) {
        updateOptions = {
          updateType: IAUUpdateKind.FLEXIBLE,
        };
        inAppUpdates.startUpdate(updateOptions);
      }
    } else {
      inAppUpdates.startUpdate(updateOptions);
    }
  }
});
SudoPlz commented 1 year ago

Hey there.

If flexible is not allowed, that's probably because updating is not allowed in general (for various reasons) - since flexible seems like the default way of handling updates and there aren't any other fallbacks. I don't know if it makes sense to stop the error that would show up upon startUpdate by checking isFlexibleUpdateAllowed, that's why it wasn't mentioned in the docs.

JameDodgers commented 1 year ago

Thanks for your quick response.

As you mentioned, as this library is just a wrapper around Google In App Updates API, throwing this error shouldn't be part of the normal usage flow in my understanding. If I previously know that the update it's not allowed, why call startUpdate and throw an error that could be avoided?

frzkn commented 1 year ago

151