To check for and initiate an update, instantiate SpInAppUpdates and call checkNeedsUpdate. If shouldUpdate is true, call startUpdate with the appropriate platform options. On Android, you must specify an updateType (either FLEXIBLE or IMMEDIATE). On iOS, the library will prompt the user to visit the App Store.
Note: If curVersion is not provided to checkNeedsUpdate, the library attempts to retrieve it automatically using react-native-device-info.
import SpInAppUpdates, {
NeedsUpdateResponse,
IAUUpdateKind,
StartUpdateOptions,
} from 'sp-react-native-in-app-updates';
const inAppUpdates = new SpInAppUpdates(
false // isDebug
);
// curVersion is optional if you don't provide it will automatically take from the app using react-native-device-info
inAppUpdates.checkNeedsUpdate({ curVersion: '0.0.8' }).then((result) => {
if (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
updateOptions = {
updateType: IAUUpdateKind.FLEXIBLE,
};
}
inAppUpdates.startUpdate(updateOptions); // https://github.com/SudoPlz/sp-react-native-in-app-updates/blob/master/src/types.ts#L78
}
});