kimxogus / react-native-version-check

A version checker for react-native applications
MIT License
722 stars 177 forks source link

iOS not working #179

Open mezalejandro opened 2 years ago

mezalejandro commented 2 years ago

Hello, on iOS i have this error: No info about this app. When i do this: VersionCheck.needUpdate().then(async res => { console.log('res ', res); // true }); I have this version: ^3.4.3

Thanks

hanabalon commented 2 years ago

This is how I was get it working:

  1. First I define this method to get app info from itunes.
    const getIOSProvider = async (appStoreURL) => {
    return await fetch(appStoreURL)
    .then((response) => {
      const res = response?.json()?.then((info) => {
        return info?.resultCount > 0 ? info.results : null
      })
      return res
    });
    }
  2. Call the method mentioned above on the component to set appVersion as a state:

const App = () => { const [appVersion, setAppVersion] = useState() // set appVersion from iTunes const [storeURL, setStoreURL] = useState('') const appStoreURL = https://itunes.apple.com/${country}/ookup?bundleId=${packageName} // iTunes API URL of your package

getIOSProvider(appStoreURL).then(res => { // call method if (res[0]) { setAppVersion(res[0].version) // marketing version setStoreURL(res[0].trackViewUrl) // I set this URL to show user the app link } })

if (appVersion) { VersionCheck.needUpdate({ currentVersion: VersionCheck.getCurrentVersion(), // this returns the version setted on the last build latestVersion: appVersion }) .then(res => console.log('VersionCheck', res)); }

HaNguyenSavvy commented 1 year ago

I have try on the postman but get this { "resultCount":0, "results": [] }