I've developed a react-native app tht is currently working (and in both the Apple and Google play stores). Last night I implemented a long overdue feature, update alert and updater using the react-native-version-check, Alert, backHandler and Linking. From this Medium blog link I adapted the function into my app and tested on Android. I testted forst my advancing my local version code/version name ahead of my store release and it works by not triggering -- works. But, when I roll back my version lower than the store's and re-build, it triggers properly with an alert box and 'update' button, when clicking the button the app closes and nothing else happens. So I do see the proper trigger happened but the update function did not. Repeating this multiple times (clicking on the app, hitting update button, app closing, I gert an error message that says 'Your Americana Radio keeps stopping' error. 'Your Americana Radio' is my app name.
The medium article/blog: https://medium.com/@kinley.tshering/force-update-react-native-apps-a9c1f22c0701
My code from my app.android.js specifically on this function as follows:
import {Alert, BackHandler, Linking} from 'react-native';
import VersionCheck from 'react-native-version-check';
const checkVersion = async () => {
try {
let updateNeeded = await VersionCheck.needUpdate();
if(updateNeeded && updateNeeded.isNeeded) {
Alert.alert (
'Please update',
'You will have to update this app to the latest version to continue using it.',
[
{
text: 'Update',
onPress: () => {
BackHandler.exitApp();
console.log("-I-: Doing the Update App functions");
Linking.openURL(updateNeeded.storeURL);
},
},
],
{cancelable: false},
);
}
} catch (error) {};
};
export default function App() {
// React Native Splash Screen
// Ref: https://dev.to/cmcodes/how-to-add-splash-screen-in-a-react-native-android-app-287l
//
// useEffect(() => {
// SplashScreen.hide();
// }, []); // Splash
const [hideSplash, setHideSplash] = useState(false);
useEffect(() => {
setTimeout(() => {
setHideSplash(true);
}, 2500); // amount of time the splash is shown from the time component is rendered
}, []);
useEffect(() => {
hideSplash && SplashScreen.hide();
}, [hideSplash]); // Splash with timer
useEffect(() => {
checkVersion();
}, []);
return(
<SocketContext.Provider value={socket}>
<AppContainer />
</SocketContext.Provider >
)
}
This is a case of 'cockpit error'.
I fixed this once I realized
updateNeeded.storeURLupdateNeeded.storeUrl.With the change, the code worked as expected.