mikehardy / react-native-update-apk

Update apk from non-play store servers, and update ios from app store in React Native.
MIT License
195 stars 57 forks source link

Support iOS updates #24

Closed strdr4605 closed 4 years ago

strdr4605 commented 4 years ago

Does this package also support iOS updates?

mikehardy commented 4 years ago

Hi there! Well, sort of. Here's what it can do on iOS - it can check for a version file (JSON format) and compare version codes to indicate if there is a new version or not. From there you can do what you like with regard to user messaging and redirection to the App Store at your apps URL or similar, but as far as I know for most devices there is no way to install an app so it cannot actually update things.

I use it this way still though, in order to pop notifications to users that they should update

strdr4605 commented 4 years ago

The version file is in the app? and it compares it with the actual app from the App Store?

mikehardy commented 4 years ago

Ah - I just checked and I actually do it all outside this module, sorry for the confusion!


  checkIOSUpdate(foreground = true, showIfCurrent = false) {
    console.log('APKUpdateService::checkIOSUpdate starting');
    fetch(AppConfig.getAppVersionUrl())
      .then(response => response.json())
      .then(async responseData => {
        console.log('APKUpdateService::checkIOSUpdate received', responseData);
        if (parseInt(responseData.versionCode) > parseInt(DeviceInfo.getBuildNumber())) {
          console.log(
            'APKUpdateService::checkIOSUpdate - have build ' + DeviceInfo.getBuildNumber()
          );
          console.log('APKUpdateService::checkIOSUpdate - inequal version codes, update?');
          firebase.notifications().setBadge(1);
          if (foreground) {
            this.displayNewVersionAlert();
          } else {
            this.displayNewVersionNotification();
          }
        } else {
          console.log('APKUpdateService::checkIOSUpdate - equal version codes');
          firebase.notifications().setBadge(0);
          if (foreground && showIfCurrent) {
            RN.Alert.alert(
              I18NService.translate('NoUpdateAvailableTitle'),
              I18NService.translate('NoUpdateAvailableText'),
              [{ text: 'OK', onPress: () => {} }]
            );
          }
        }
      })
      .catch(e => {
        console.log('APKUpdateService::checkIOSUpdate error', e);
      });
  }