sp-react-native-in-app-updates: Failed to check or start update: [TypeError: Cannot read property 'checkNeedsUpdate' of null]

Don’t know why but I’m getting this error Although , I have installed it correctly & getting the inAppUpdates all props

import SpInAppUpdates, { NeedsUpdateResponse, IAUUpdateKind, StartUpdateOptions, } from “sp-react-native-in-app-updates”

SplashScreen.preventAutoHideAsync()

function IgniteApp() { const inAppUpdates = new SpInAppUpdates(false)

const checkAndUpdateApp = async () => { try { console.log(“Before checkNeedsUpdate:”, inAppUpdates) const result = await inAppUpdates.checkNeedsUpdate() console.log(“Update result:”, result)

  if (result.shouldUpdate) {
    let updateOptions: StartUpdateOptions = {}

    if (Platform.OS === "android") {
      updateOptions = {
        updateType: IAUUpdateKind.IMMEDIATE,
      }
      await inAppUpdates.startUpdate(updateOptions)
    } else {
      console.log("Update available. Please visit the App Store to update the app.")
    }
  }
} catch (error) {
  console.error("Failed to check or start update:", error)
}

}

React.useEffect(() => { async function onFetchUpdateAsync() { try { const update = await Updates.checkForUpdateAsync()

    if (update.isAvailable) {
      await Updates.fetchUpdateAsync()
      await Updates.reloadAsync()
    }
  } catch (error) {
    console.log("RTTTR", error)
    alert(`Error fetching latest Expo update: ${error}`)
  }
}
console.log("FFff-----", __DEV__)
if (!__DEV__) {
  onFetchUpdateAsync()
}
checkAndUpdateApp()

}, [])

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 16 (1 by maintainers)

Most upvoted comments

Got it, thank you! But I’m trying to use android in-app updates API, react-native-store-version only makes fetch request

@iliapnmrv is your app published ? make sure your app should be published

const check = await checkVersion({ androidStoreURL: "Your app url, country: “np”, }); try to console this with your app url and try with any playstore url “https://play.google.com/store/apps/details?id=com.dts.freefireth”

Thanks for that it has worked with this code


useEffect(() => {
    const init = async () => {
      try {
        if (Platform.OS === "android") {
          const check = await checkVersion({
            version: AppConfig.ios_app_version, // app local version
            iosStoreURL: AppConfig.iosUrl,
            androidStoreURL: AppConfig.playStoreUrl,
            country: "jp", // default value is 'jp'
          });

          if (check.result === "new") {
            // if app store version is new
            console.log("new version");
            Alert.alert(
              "New Version Available",
              "New version available! Please update the app to the latest version",
              [
                {
                  text: "Cancel",
                  onPress: () => console.log("Cancel Pressed"),
                  style: "cancel",
                },
                {
                  text: "Update",
                  onPress: () => {
                    console.log("OK Pressed");
                    // lets open  the  playstore app url on android
                    Linking.openURL(AppConfig.playStoreUrl);
                  },
                },
              ]
              // { cancelable: false }
            );
          } else {
            console.log("latest version");
          }
        } else {
          console.log("not android");
          console.log("ios updates coming  soon");
        }
      } catch (e) {
        console.log(e);
      }
    };

    init();
  }, []);
  
  
```
Thanks  for your advice .