Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install the update on next start of app. #139

Open
shahanshah-cutshort opened this issue Apr 5, 2023 · 1 comment
Open

install the update on next start of app. #139

shahanshah-cutshort opened this issue Apr 5, 2023 · 1 comment

Comments

@shahanshah-cutshort
Copy link

shahanshah-cutshort commented Apr 5, 2023

Thanks for great package.
I am implementing this package with IAUUpdateKind.FLEXIBLE and its working fine. But I want to just download the update.
And install the update on start of App later next time.
Sometime its working sometime it doesn't

I tried:-
readStorage and writeStorage are AsyncStorage function to read and write.

const inAppUpdates = new SpInAppUpdates(false);
   useEffect(() => {
     handleAppUpdate();
   }, []);
   const handleAppUpdate = async () => {
    readStorage('isAppUpdateAvailable').then((updateAvailable) => {
      if (updateAvailable) {
        inAppUpdates.installUpdate();
        writeStorage('isAppUpdateAvailable', null);
      }
    });
    };
   const checkAutoUpdate = () => {
    const listener = ({ status }) => {
      if (status === IAUInstallStatus.DOWNLOADED) {
        writeStorage('isAppUpdateAvailable', 'isAppUpdateAvailable');
        //inAppUpdates.installUpdate();
      }
    };
    try {
      // curVersion is optional if you don't provide it will automatically take from the app using react-native-device-info
      inAppUpdates.checkNeedsUpdate().then((result) => {
        if (result.shouldUpdate) {
          console.log('result.shouldUpdate', result.shouldUpdate);

          let updateOptions: StartUpdateOptions = {};
          if (Platform.OS === 'android') {
            // android only, on iOS the user will be promped to go to your app store page
            inAppUpdates.addStatusUpdateListener(listener);
            updateOptions = {
              updateType: IAUUpdateKind.FLEXIBLE,
            };
          } else {
            updateOptions = {
              title: 'Update available',
              message:
                'There is a new version of Cutshort available on the App Store, do you want to update it?',
              buttonUpgradeText: 'Update',
              buttonCancelText: 'Cancel',
            };
          }
          inAppUpdates.startUpdate(updateOptions);
        }
      });
     } catch (error) {
      console.log('___ERROR', error);
     }
    };
@Lepidopterolog
Copy link

Lepidopterolog commented Apr 5, 2023

@shahanshah-cutshort
I have already written about this in a previous issue:
#138
#138 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants