### Start Example App Packager Source: https://github.com/aravind3566/react-native-in-app-updates/blob/main/CONTRIBUTING.md Starts the Metro server for the example application. This is necessary to run the example app. ```sh yarn example start ``` -------------------------------- ### Run Example App on iOS Source: https://github.com/aravind3566/react-native-in-app-updates/blob/main/CONTRIBUTING.md Builds and runs the example application on an iOS simulator or device. ```sh yarn example ios ``` -------------------------------- ### Run Example App on Android Source: https://github.com/aravind3566/react-native-in-app-updates/blob/main/CONTRIBUTING.md Builds and runs the example application on an Android device or emulator. ```sh yarn example android ``` -------------------------------- ### Install react-native-in-app-updates Source: https://context7.com/aravind3566/react-native-in-app-updates/llms.txt Use npm or yarn to install the library. Remember to rebuild the native app after installation. ```sh npm install react-native-in-app-updates # or yarn add react-native-in-app-updates ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/aravind3566/react-native-in-app-updates/blob/main/CONTRIBUTING.md Run this command in the root directory to install all project dependencies using Yarn workspaces. ```sh yarn ``` -------------------------------- ### Start Metro Server (npm/Yarn) Source: https://github.com/aravind3566/react-native-in-app-updates/blob/main/example/README.md Initiates the Metro JavaScript bundler, essential for React Native development. Run this command from the root of your project. ```bash # using npm npm start # OR using Yarn yarn start ``` -------------------------------- ### Install react-native-in-app-updates Source: https://github.com/aravind3566/react-native-in-app-updates/blob/main/README.md Install the package using npm. ```sh npm install react-native-in-app-updates ``` -------------------------------- ### Check for Updates and Trigger Flows Source: https://context7.com/aravind3566/react-native-in-app-updates/llms.txt This example demonstrates how to check for available updates and trigger either a flexible or immediate update flow. It includes error handling for various scenarios, such as non-Android platforms or invalid update flows. The flexible update downloads silently, while the immediate update requires user interaction. ```typescript import { useEffect, useState } from 'react'; import { Platform, Text, View, Button } from 'react-native'; import { checkForUpdate, UpdateFlow } from 'react-native-in-app-updates'; export default function App() { const [status, setStatus] = useState('Idle'); // Trigger a flexible update check on mount useEffect(() => { if (Platform.OS !== 'android') { setStatus('In-app updates are Android-only'); return; } triggerFlexibleUpdate(); }, []); async function triggerFlexibleUpdate() { try { // Resolves with "Flexible update started" or "No update available" const result = await checkForUpdate(UpdateFlow.FLEXIBLE); setStatus(result); } catch (e: any) { // e.message contains one of: // "This library is only available on Android." // "Invalid update flow. Use UpdateFlow.IMMEDIATE or UpdateFlow.FLEXIBLE." // "NO_ACTIVITY" / "UPDATE_CHECK_FAILED" from the native side setStatus(`Error: ${e.message}`); } } async function triggerImmediateUpdate() { try { // Blocks until the user completes or cancels the update const result = await checkForUpdate(UpdateFlow.IMMEDIATE); // result === "Update flow finished" setStatus(result); } catch (e: any) { // e.message === "UPDATE_CANCELLED" if the user dismissed the dialog // e.message === "NOT_ALLOWED" if the Play Store disallows immediate updates setStatus(`Error: ${e.message}`); } } return ( Status: {status}