sp-react-native-in-app-updates icon indicating copy to clipboard operation
sp-react-native-in-app-updates copied to clipboard

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

Open JameDodgers opened this issue 2 years ago • 3 comments

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);
    }
  }
});

JameDodgers avatar Feb 03 '23 23:02 JameDodgers

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.

SudoPlz avatar Feb 03 '23 23:02 SudoPlz

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?

JameDodgers avatar Feb 04 '23 01:02 JameDodgers

#151

frzkn avatar Jul 03 '23 07:07 frzkn