Skip to content

In IOS getLatestVersion is not working #104

Open

Description

@ChandreshRana

I tried following for IOS:

===================== First Method =============================

VersionCheck.getLatestVersion({
provider: 'appStore' // for Ios
})
.then(latestVersion => {
console.log(latestVersion);
});

===================== Second Method ===========================

VersionCheck.getLatestVersion().then(latestVersion => {
console.log(latestVersion);
});

===================== Third Method ===========================

VersionCheck.getLatestVersion({
forceUpdate: true,
provider: () => fetch(https://itunes.apple.com/${countryCode}lookup?bundleId=${packageName})
.then(r => r.json())
.then(({version}) => version)
}).then(latestVersion =>{
console.log(latestVersion);
});

  • Nothing get Response as Latest Verison of IOS App from appstore.

  • @kimxogus suggest any additional parameters or api changes for get latest version info

Activity

  1. jessejiang0214 commented on Feb 14, 2020

    @jessejiang0214

    Hi @ChandreshRana ,

    I fixed this issue yesterday, but it looks like not this component issue, it's iTunes API's issue.

    If you check the provider, you will find that the countryCode is all uppercase like "AU", the funny thing is if you put AU into query url like https://itunes.apple.com/AU/ookup?bundleId=${packageName}, it returns the previous version, for example, 1.2.33.
    But as I release the new version 1.2.34 in the morning that query still returns me 1.2.33
    If the query is https://itunes.apple.com/au/ookup?bundleId=${packageName}, lowercase au. That can return 1.2.34

    So the solution is we provide country as the parameter.
    like VersionCheck.getLatestVersion({country:'au'})

  2. thanhluantl2304 commented on Mar 14, 2020

    @thanhluantl2304

    Thanks @jessejiang0214! But that should be added to the documentation! :D

  3. antonioreyna commented on Jun 3, 2020

    @antonioreyna

    yes same here, it worked defining the country manually at least for ios i need to check if for andorid

  4. gabcvit commented on Feb 18, 2021

    @gabcvit

    @antonioreyna I just had a test on android for this function, it worked quite well (really late response, I know, I only came across this repo yesterday) 😄

  5. aperomingo commented on Apr 15, 2021

    @aperomingo

    Hi, I have tried to do the three methods that you comment before and I had the same result: undefined.

    Searching from google i found this example https://itunes.apple.com/lookup?bundleId=${bundleId}&country=${countryCode} which give me the version and others values like appName, appDescription, minimumOsVersion, currency and +20 more values...
    I think the way to take the version from the App Store (provider: 'appStore') has changed and this library doesn't update this.

    My code:
    iosUpdateUrl = https://itunes.apple.com/lookup?bundleId=${bundleId}&country=${countryCode}

      getIosProvider(iosUpdateUrl) {
        return () =>
          fetch(iosUpdateUrl).then((response) =>
            response?.json()?.then((info) => (info?.resultCount > 0 ? info.results[0].version : null)),
          );
      },
    
      updateAppMessage(iosUpdateUrl) {
        return VersionCheck.getLatestVersion({
          provider: Platform.OS === 'ios' ? this.getIosProvider(iosUpdateUrl) : 'playStore',
        })
          .then((latestVersion) =>
            !!latestVersion ? VersionCheck.getCurrentVersion() !== latestVersion : false,
          )
          .catch((error) => {
            console.log('error taking app version', error);
            return false;
          });
      }
    

    With this 2 methods i know if i have to display the update app flow or not

    Used libraries versions

    "react-native-version-check": "^3.4.2" (latest actually)
    "react-native": "0.63.3"

    Source: https://medium.com/usemobile/get-app-version-from-app-store-and-more-e43c5055156a

  6. aperomingo commented on Apr 19, 2021

    @aperomingo

    Update: previous method doesn't work on iOS Release (App Store) but yes on Debug and Release using simulator/physical iPhone... Android is OK

    On testing now:

      getIosProvider(iosUpdateUrl) {
        return () =>
          fetch(iosUpdateUrl).then((response) =>
            response?.json()?.then((info) => (info?.resultCount > 0 ? info.results[0].version : null)),
          );
      }
    
      updateAppMessage(iosUpdateUrl) {
        return VersionCheck.needUpdate({
          provider: Platform.OS === 'ios' ? this.getIosProvider(iosUpdateUrl) : 'playStore',
        })
          .then(async (res) => {
            return typeof res?.isNeeded === 'boolean' ? res?.isNeeded : false;
          })
          .catch((error) => {
            console.log('error taking app version', error);
            return false;
          });
      }
    
  7. pinned this issue on May 22, 2021
  8. TomasBarry commented on Mar 9, 2022

    @TomasBarry

    Is the issue not with this line?

    return fetch(
      `https://itunes.apple.com/${countryCode}lookup?bundleId=${opt.packageName}&date=${dateNow}`, // this line
      opt.fetchOptions
    )

    Unpacking that:

    https://itunes.apple.com/${countryCode}lookup?bundleId=${opt.packageName}&date=${dateNow}

    Can become (removing date for simplicity):

    https://itunes.apple.com/GBlookup?bundleId=com.XXX.YYY

    Look at the countryCode though, there's no / between it and the lookup URL parameter.

    I've verified that putting a / after countryCode and before lookup downloads the JSON as expected so the fix is to amend that fetch to be:

    return fetch(
      `https://itunes.apple.com/${countryCode}/lookup?bundleId=${opt.packageName}&date=${dateNow}`,
      opt.fetchOptions
    )

    That is what I'd suspect? Can you confirm @kimxogus

  9. harshsanghani commented on Apr 15, 2022

    @harshsanghani

    I did this and it works

       try {
            let versionConfig = {};
            const currentVersion = VersionCheck.getCurrentVersion();
            if (Platform.OS === "ios") {
              const packageName = await VersionCheck.getPackageName();
              const countryName = await VersionCheck.getCountry();
              versionConfig["provider"] = () =>
                fetch(`https://itunes.apple.com/${countryName.toLowerCase()}/lookup?bundleId=${packageName}`)
                  .then(r => r.json())
                  .then((res) => res?.results[0]?.version || currentVersion);
            }
            const latestVersion = await VersionCheck.getLatestVersion(versionConfig);
            const updateNeeded = await VersionCheck.needUpdate({
              latestVersion,
              currentVersion,
              provider: Platform.OS === "ios" ? "appStore" : "playStore",
            });
            if (updateNeeded && updateNeeded?.isNeeded) {
              Alert.alert("Version Update", "Update your app for the newest features", [
                { text: "Cancel", style: "cancel" },
                { text: "Update", style: "default", onPress: () => onUpdatePress() },
              ], { cancelable: false });
            }
          } catch (error) {
            console.log("error", error);
          }
    
  10. sachiotomita commented on Aug 5, 2022

    @sachiotomita

    the example to get latestVersion for iOS
    ( fetch from API

          let latestVersion;
    
          if (Platform.OS === 'ios') {
            const packageName = await VersionCheck.getPackageName();
            const countryName = 'jp'; // getCountry() seems not correct..
            console.log(packageName);
    
            latestVersion = await fetch(
              `https://itunes.apple.com/${countryName.toLowerCase()}/lookup?bundleId=${packageName}`,
            )
              .then(r => r.json())
              .then(res => {
                console.log(res);
                return res?.results[0]?.version;
              });
          } else {
            latestVersion = await VersionCheck.getLatestVersion();
          }
    
          console.log(latestVersion);
    
  11. BraveEvidence commented on Feb 26, 2023

    @BraveEvidence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions