SudoPlz / sp-react-native-in-app-updates

An in-app updater for the native version of your react-native app.
MIT License
484 stars 66 forks source link

Failed to check or start update: [TypeError: Cannot read property 'checkNeedsUpdate' of null] #179

Open UtkarshFSD opened 5 months ago

UtkarshFSD commented 5 months ago

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()

}, [])

27ksandip commented 4 months ago

same error TypeError: Cannot read property 'displayName' of undefined, js engine: hermes ERROR TypeError: Cannot read property 'checkNeedsUpdate' of null any one can help ?

SudoPlz commented 4 months ago

this is interesting. Is this a vanilla react-native app? (iOS or Android)? I'm asking because this library is using .ios.ts or .android.ts file name extensions which metro bundler knows how to handle. (I suspect that something on your environment may be different?)

27ksandip commented 4 months ago

this is interesting. Is this a vanilla react-native app? (iOS or Android)? I'm asking because this library is using .ios.ts or .android.ts file name extensions which metro bundler knows how to handle. (I suspect that something on your environment may be different?)

@SudoPlz I am using react native expo and try to add update feature (no typescript )

malaiandrei commented 4 months ago

i have the same problem react-native@0.72.12 has anyone found a solution?

lewismunene020 commented 3 months ago

i also have the same problem in expo @SudoPlz what might the issue

27ksandip commented 3 months ago

@lewismunene020 @malaiandrei You need to publish your app on the Play Store, and then it will be fixed automatically. If you debug in detail, you might see an error like "package name could not be found" or something similar. However, once the app is published, it works fine.

lewismunene020 commented 3 months ago

the app is already on playstore currently so i guess the package name is present at the monent

27ksandip commented 3 months ago

the app is already on playstore currently so i guess the package name is present at the monent

is production released ? if not you will face this issue

lewismunene020 commented 3 months ago

so there is an app in production and am adding the feature into an existing app but i just keep getting the error

27ksandip commented 3 months ago

useEffect(() => { const init = async () => { try { const currentAppVersion = Constants.expoConfig.version;

    const check = await checkVersion({
      version: currentAppVersion,
      androidStoreURL:
        "enter_app_url: "np",
    });
    if (check.result === "new") {
      setIsUpdateAvailable(true);
    }
  } catch (e) {
    showMessage({
      message: "Something went wrong",
      type: "danger",
    });
  }
};

init();

}, []);

you can try this package react-native-store-version its working fine in my app https://www.npmjs.com/package/react-native-store-version

lewismunene020 commented 3 months ago

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 .