HotUpdater.runUpdateProcess()
The HotUpdater.runUpdateProcess
function allows you to manually check for and apply updates at any point in your application’s lifecycle. This flexibility is useful when updates need to align with specific user flows or app states, rather than being triggered automatically at the entry point.
Key Features
- Manual Update Control: You can run the update process on demand, giving you more control over how and when updates occur.
- Configurable Restart Logic: The
reloadOnForceUpdate
option lets you choose whether the app should automatically restart for forced updates or return control to the developer for handling the restart.
Usage
Here's an example of how to use HotUpdater.runUpdateProcess
to check for updates and handle them appropriately:
reloadOnForceUpdate
istrue
When a force update exists, the app will automatically reload.
import { HotUpdater, getUpdateSource } from "@hot-updater/react-native";
const result = await HotUpdater.runUpdateProcess({
source: getUpdateSource("<your-update-server-url>", {
updateStrategy: "fingerprint", // or "appVersion"
}),
requestHeaders: {
// Add any necessary request headers here
},
reloadOnForceUpdate: true, // Automatically reload the app on force updates
});
reloadOnForceUpdate
isfalse
When a force update exists, the app will not reload. shouldForceUpdate
will be returned as true
.
const result = await HotUpdater.runUpdateProcess({
source: getUpdateSource("<your-update-server-url>", {
updateStrategy: "fingerprint", // or "appVersion"
}),
requestHeaders: {
// Add any necessary request headers here
},
reloadOnForceUpdate: false, // The app won't reload on force updates
});
// If status is UP_TO_DATE, other fields shouldForceUpdate, id will not be present.
if(result.status !== "UP_TO_DATE" && result.shouldForceUpdate) {
// You can handle the restart manually here
HotUpdater.reload();
}
Return Value
HotUpdater.runUpdateProcess
returns an object with the following properties:
Property | Type | Description |
---|
status | "ROLLBACK" | "UPDATE" | "UP_TO_DATE" | The status of the update process |
shouldForceUpdate | boolean | Whether the update process is forced |
id | string | The ID of the bundle to update |
message | string | The message of the update process |
Custom source Function
You can pass an async function to the source option for full control over how update info is fetched.
const result = await HotUpdater.runUpdateProcess({
source: async ({
platform,
appVersion,
channel,
minBundleId,
bundleId,
fingerprintHash,
_updateStrategy,
}) => {
const res = await fetch("https://your.api/update-info");
return (await res.json()) as AppUpdateInfo | null;
},
// ... other options
});