### Start Metro Server for Example App Source: https://github.com/vantuan88291/react-native-ota-hot-update/blob/main/CONTRIBUTING.md Starts the Metro bundler to serve the example application. This is necessary for running the example app on a device or simulator. ```sh yarn example start ``` -------------------------------- ### Installation and Configuration Source: https://context7.com/vantuan88291/react-native-ota-hot-update/llms.txt Instructions for installing the library and configuring it for iOS, Android, and Expo projects. ```APIDOC ## Installation ### Install the Package ```bash # Install with blob-util for download management yarn add react-native-ota-hot-update && yarn add react-native-blob-util # For iOS cd ios && pod install ``` ### iOS Configuration (AppDelegate.mm) ```objective-c #import "OtaHotUpdate.h" - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { #if DEBUG return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; #else return [OtaHotUpdate getBundle]; #endif } ``` ### iOS Configuration for React Native 0.77+ (AppDelegate.swift) ```swift import react_native_ota_hot_update override func bundleURL() -> URL? { #if DEBUG RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index") #else OtaHotUpdate.getBundle() #endif } ``` ### Android Configuration (MainApplication.kt) ```kotlin import com.otahotupdate.OtaHotUpdate override val reactNativeHost: ReactNativeHost = object : DefaultReactNativeHost(this) { override fun getJSBundleFile(): String? { return OtaHotUpdate.bundleJS(this@MainApplication) } } ``` ### Expo Configuration (app.json) ```json { "plugins": [ "react-native-ota-hot-update" ] } ``` ``` -------------------------------- ### Complete Update Flow Example in TypeScript Source: https://context7.com/vantuan88291/react-native-ota-hot-update/llms.txt This snippet demonstrates a full implementation of checking for updates, downloading new versions, and installing them with UI feedback. It requires setting up an update API endpoint and handling platform-specific download URLs. The `hotUpdate.downloadBundleUri` function is used for the download and installation process, with callbacks for progress and success/failure. ```typescript import React, { useState, useEffect } from 'react'; import { View, Text, Button, Alert, StyleSheet } from 'react-native'; import hotUpdate from 'react-native-ota-hot-update'; import ReactNativeBlobUtil from 'react-native-blob-util'; import { Platform } from 'react-native'; const UPDATE_API = 'https://your-server.com/api/update.json'; export default function UpdateScreen() { const [currentVersion, setCurrentVersion] = useState(0); const [downloadProgress, setDownloadProgress] = useState(0); const [isUpdating, setIsUpdating] = useState(false); useEffect(() => { hotUpdate.getCurrentVersion().then(setCurrentVersion); }, []); const checkAndUpdate = async () => { try { const response = await fetch(UPDATE_API); const updateInfo = await response.json(); if (updateInfo.version <= currentVersion) { Alert.alert('Up to Date', 'You have the latest version.'); return; } Alert.alert( 'Update Available', `Version ${updateInfo.version} is available. ${updateInfo.releaseNotes || ''}`, [ { text: 'Later', style: 'cancel' }, { text: 'Update Now', onPress: () => downloadUpdate(updateInfo) } ] ); } catch (error) { Alert.alert('Error', 'Failed to check for updates'); } }; const downloadUpdate = async (updateInfo: any) => { setIsUpdating(true); setDownloadProgress(0); const url = Platform.OS === 'ios' ? updateInfo.downloadIosUrl : updateInfo.downloadAndroidUrl; hotUpdate.downloadBundleUri(ReactNativeBlobUtil, url, updateInfo.version, { progress: (received, total) => { setDownloadProgress((+received / +total) * 100); }, updateSuccess: () => { setIsUpdating(false); Alert.alert('Success', 'Update installed!', [ { text: 'Restart Now', onPress: () => hotUpdate.resetApp() } ]); }, updateFail: (message) => { setIsUpdating(false); Alert.alert('Update Failed', message || 'Unknown error'); }, maxBundleVersions: 3, metadata: { releaseNotes: updateInfo.releaseNotes } }); }; return ( Current Version: {currentVersion} {isUpdating && ( {downloadProgress.toFixed(0)}% )}