sp-react-native-in-app-updates
sp-react-native-in-app-updates copied to clipboard
install the update on next start of app.
Thanks for great package.
I am implementing this package with IAUUpdateKind.FLEXIBLE
and its working fine. But I want to just download the update.
And install the update on start of App later next time.
Sometime its working sometime it doesn't
I tried:-
readStorage
and writeStorage
are AsyncStorage
function to read and write.
const inAppUpdates = new SpInAppUpdates(false);
useEffect(() => {
handleAppUpdate();
}, []);
const handleAppUpdate = async () => {
readStorage('isAppUpdateAvailable').then((updateAvailable) => {
if (updateAvailable) {
inAppUpdates.installUpdate();
writeStorage('isAppUpdateAvailable', null);
}
});
};
const checkAutoUpdate = () => {
const listener = ({ status }) => {
if (status === IAUInstallStatus.DOWNLOADED) {
writeStorage('isAppUpdateAvailable', 'isAppUpdateAvailable');
//inAppUpdates.installUpdate();
}
};
try {
// curVersion is optional if you don't provide it will automatically take from the app using react-native-device-info
inAppUpdates.checkNeedsUpdate().then((result) => {
if (result.shouldUpdate) {
console.log('result.shouldUpdate', result.shouldUpdate);
let updateOptions: StartUpdateOptions = {};
if (Platform.OS === 'android') {
// android only, on iOS the user will be promped to go to your app store page
inAppUpdates.addStatusUpdateListener(listener);
updateOptions = {
updateType: IAUUpdateKind.FLEXIBLE,
};
} else {
updateOptions = {
title: 'Update available',
message:
'There is a new version of Cutshort available on the App Store, do you want to update it?',
buttonUpgradeText: 'Update',
buttonCancelText: 'Cancel',
};
}
inAppUpdates.startUpdate(updateOptions);
}
});
} catch (error) {
console.log('___ERROR', error);
}
};
@shahanshah-cutshort I have already written about this in a previous issue: https://github.com/SudoPlz/sp-react-native-in-app-updates/issues/138 https://github.com/SudoPlz/sp-react-native-in-app-updates/issues/138#issuecomment-1491734995