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

install the update on next start of app.

Open shahanshah-cutshort opened this issue 1 year ago • 1 comments

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

shahanshah-cutshort avatar Apr 05 '23 10:04 shahanshah-cutshort

@shahanshah-cutshort I have already written about this in a previous issue: https://github.com/SudoPlz/sp-react-native-in-app-updates/issues/138 https://github.com/SudoPlz/sp-react-native-in-app-updates/issues/138#issuecomment-1491734995

Lepidopterolog avatar Apr 05 '23 14:04 Lepidopterolog