### Start Metro Packager for Example App Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/CONTRIBUTING.md Starts the Metro bundler, which serves the JavaScript code for the React Native example application. This allows for live reloading of JavaScript changes. ```sh yarn example start ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/CONTRIBUTING.md Installs all required dependencies for the project using Yarn. It is the initial step to set up the development environment. ```sh yarn ``` -------------------------------- ### Project Development Scripts Reference Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/CONTRIBUTING.md A comprehensive list of available `yarn` scripts defined in `package.json` for common development tasks, including project setup, type checking, linting, testing, and running the example application. ```APIDOC yarn bootstrap: setup project by installing all dependencies and pods. yarn typescript: type-check files with TypeScript. yarn lint: lint files with ESLint. yarn test: run unit tests with Jest. yarn example start: start the Metro server for the example app. yarn example android: run the example app on Android. yarn example ios: run the example app on iOS. ``` -------------------------------- ### Run Example App on iOS Simulator/Device Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/CONTRIBUTING.md Builds and runs the example React Native application on an iOS simulator or connected device. This is used to test changes in a real environment. ```sh yarn example ios ``` -------------------------------- ### Run Example App on Android Device/Emulator Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/CONTRIBUTING.md Builds and runs the example React Native application on a connected Android device or emulator. This is used to test changes in a real environment. ```sh yarn example android ``` -------------------------------- ### Install sp-react-native-in-app-updates via npm Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/README.md Command to install the `sp-react-native-in-app-updates` package and save it as a dependency in your project. ```Shell $ npm install sp-react-native-in-app-updates --save ``` -------------------------------- ### Basic In-App Update Check and Start Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/README.md Demonstrates how to initialize `SpInAppUpdates`, check for available updates using `checkNeedsUpdate`, and initiate an update with `startUpdate`. It includes conditional logic for Android's flexible update type. ```JavaScript 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 } }); ``` -------------------------------- ### API: installUpdate - Install Downloaded Update (Android only) Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/README.md Installs a previously downloaded update. This method is specific to Android and is typically called after an update has been successfully downloaded in the background. ```APIDOC installUpdate() : void Description: Installs a downloaded update. (Android only) ``` -------------------------------- ### Configure Android SDK and NDK Paths in local.properties Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/android/README.md This snippet shows the required entries for the `local.properties` file, which points to the Android SDK and NDK installations. These paths are crucial for Gradle to correctly locate the necessary build tools and libraries for Android projects. ```Properties ndk.dir=/Users/{username}/Library/Android/sdk/ndk-bundle sdk.dir=/Users/{username}/Library/Android/sdk ``` -------------------------------- ### Add Status Update Listener (Android) Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/README.md Adds a listener to track the current status of in-app update downloads. This callback provides details on the installation status, bytes downloaded, and total bytes to download. This functionality is specific to Android. ```APIDOC addStatusUpdateListener(callback: (status: StatusUpdateEvent) : void) : void (Android only) Parameters: callback: (status: StatusUpdateEvent) : void - Callback function to receive status updates. StatusUpdateEvent: status: [AndroidInstallStatus] - The status of the installation (https://developer.android.com/reference/com/google/android/play/core/install/model/InstallStatus) bytesDownloaded: int - How many bytes were already downloaded totalBytesToDownload: int - The total amount of bytes in the update ``` -------------------------------- ### API: startUpdate - Initiate In-App Update Prompt Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/README.md Shows a pop-up asking the user if they want to update, giving them the option to download the said update. This method handles the user-facing prompt and initiates the update process based on the provided options. ```APIDOC startUpdate(updateOptions: StartUpdateOptions) : Promise Description: Shows pop-up asking user if they want to update, giving them the option to download said update. Parameters: updateOptions: StartUpdateOptions Properties: updateType (Android ONLY): (required on Android) IAUUpdateKind Description: Either IAUUpdateKind.FLEXIBLE or IAUUpdateKind.IMMEDIATE. This uses play-core below the hood, read more here about the two modes. title (iOS only): (optional) String Description: The title of the alert prompt when there's a new version. (default: 'Update Available') message (iOS only): (optional) String Description: The content of the alert prompt when there's a new version (default: 'There is an updated version available on the App Store. Would you like to upgrade?') buttonUpgradeText (iOS only): (optional) String Description: The text of the confirmation button on the alert prompt (default: 'Upgrade ') buttonCancelText (iOS only): (optional) String Description: The text of the cancelation button on the alert prompt (default: 'Cancel') forceUpgrade (iOS only): (optional) Boolean Description: If set to true the user won't be able to cancel the upgrade (default: 'false') bundleId (iOS only): (optional) String Description: The id that identifies the app (ex: com.apple.mobilesafari). If undefined, it will be retrieved with react-native-device-info. (default: 'undefined') country (iOS only): (optional) String Description: If set, it will filter by country code while requesting an update, The value should be ISO 3166-1 country code (default: 'undefined') versionSpecificOptions (iOS only): (optional) Array Description: An array of IosStartUpdateOptionWithLocalVersion that specify rules dynamically based on what version the device is currently running. (default: 'undefined') ``` -------------------------------- ### SpInAppUpdates.startUpdate Method Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/README.md Initiates the update process. The behavior depends on the platform and `updateOptions`. ```APIDOC SpInAppUpdates.startUpdate(updateOptions?: StartUpdateOptions): void updateOptions: (Optional) Configuration for the update process. For Android: updateType: IAUUpdateKind (e.g., IAUUpdateKind.FLEXIBLE, IAUUpdateKind.IMMEDIATE) For iOS: title?: string: Title for the update prompt. message?: string: Message for the update prompt. buttonUpgradeText?: string: Text for the upgrade button. buttonCancelText?: string: Text for the cancel button. country?: string: Country code for the App Store lookup. ``` -------------------------------- ### StartUpdateOptions Interface Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/README.md Interface defining the options for `startUpdate` method, varying by platform. ```APIDOC StartUpdateOptions: // Android specific: updateType?: IAUUpdateKind // iOS specific: title?: string message?: string buttonUpgradeText?: string buttonCancelText?: string country?: string ``` -------------------------------- ### Publish New Project Version to npm Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/CONTRIBUTING.md Uses `release-it` to automate the process of publishing new versions to npm, including bumping versions based on semver, creating tags, and releases. ```sh yarn release ``` -------------------------------- ### Configure iOS Info.plist for App Store Deep Link Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/README.md Add `LSApplicationQueriesSchemes` to your iOS `Info.plist` to allow launching the App Store deep link for updates. ```XML LSApplicationQueriesSchemes itms-apps ``` -------------------------------- ### Execute Project Unit Tests Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/CONTRIBUTING.md Runs the unit tests for the project using Jest to verify functionality and prevent regressions. It's recommended to add tests for new changes. ```sh yarn test ``` -------------------------------- ### SpInAppUpdates Class Reference Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/README.md The main class for managing in-app updates. It provides methods to check for updates and initiate the update process. ```APIDOC SpInAppUpdates: __init__(isDebug: boolean) isDebug: A boolean indicating whether to run in debug mode. (e.g., false for production) ``` -------------------------------- ### Automatically Fix ESLint Formatting Issues Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/CONTRIBUTING.md Runs ESLint with the `--fix` flag to automatically resolve common formatting and linting errors, helping maintain consistent code style. ```sh yarn lint --fix ``` -------------------------------- ### Verify Code Quality with TypeScript and ESLint Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/CONTRIBUTING.md Executes TypeScript type checking and ESLint linting to ensure code quality and adherence to coding standards before committing changes. ```sh yarn typescript yarn lint ``` -------------------------------- ### Replace react-native-device-info for Expo compatibility Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/README.md Create a custom `react-native-device-info.js` file to provide `getBundleId` and `getVersion` using `expo-constants`, necessary for Expo projects. ```JavaScript import Constants from "expo-constants" export const getBundleId = () => { return Constants.expoConfig?.ios?.bundleIdentifier ?? ''; } export const getVersion = () => { return Constants.expoConfig?.version } export default { getBundleId, getVersion, }; ``` -------------------------------- ### Configure Babel module-resolver for Expo device info alias Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/README.md Add an alias in your `babel.config.js` to redirect `react-native-device-info` imports to your custom Expo-compatible implementation. ```JavaScript plugins: [ [ 'module-resolver', { root: ['.'], alias: { 'react-native-device-info': './react-native-device-info.js' } } ], // ... ] ``` -------------------------------- ### Configure Expo app.json for iOS App Store Deep Link Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/README.md Add `LSApplicationQueriesSchemes` within the `ios.infoPlist` section of your Expo `app.json` or `app.config.json` for iOS deep linking. ```JSON "ios": { "infoPlist": { "LSApplicationQueriesSchemes": ["itms-apps"] } }, ``` -------------------------------- ### SpInAppUpdates.checkNeedsUpdate Method Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/README.md Checks if a new version of the app is available. Returns a Promise that resolves with a `NeedsUpdateResponse` object. ```APIDOC SpInAppUpdates.checkNeedsUpdate(options: object): Promise options: curVersion?: string: (Optional) The current version of the app. If not provided, it's taken from react-native-device-info. country?: string: (Optional, iOS only) The country code to check for specific app store versions (e.g., 'it'). Returns: Promise ``` -------------------------------- ### NeedsUpdateResponse Interface Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/README.md Interface defining the structure of the response from `checkNeedsUpdate`. ```APIDOC NeedsUpdateResponse: shouldUpdate: boolean // ... other potential properties (not explicitly shown but implied by 'result.shouldUpdate') ``` -------------------------------- ### Check for App Updates (checkNeedsUpdate) Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/README.md Checks if there are any updates available for the application. This function takes `CheckOptions` as input and returns a `Promise` that resolves to a `NeedsUpdateResponse` object, indicating whether an update is needed and providing details about the store version. ```APIDOC function checkNeedsUpdate(checkOptions: CheckOptions) : Promise CheckOptions: curVersion: (required) String The semver of your current app version toSemverConverter: (optional) Function This will run right after the store version is fetched in case you want to change it before it's compared as a semver customVersionComparator: (optional) Function By default this library uses `semver` behind the scenes to compare the store version with the `curVersion` value, but you can pass your own version comparator if you want to country: (optional) String (iOS only) default `undefined`, it will filter by country code while requesting an update, The value should be [ISO 3166-1 country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements) NeedsUpdateResponse: shouldUpdate: Boolean Whether there's a newer version on the store or not storeVersion: String The latest app/play store version we're aware of other: Object Other info returned from the store (differs on Android/iOS) ``` -------------------------------- ### In-App Update Check with Country-Specific iOS Options Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/README.md Shows how to check for updates for a specific country (iOS only) and customize the update prompt's title, message, and button texts. Android updates use `IMMEDIATE` type. ```JavaScript inAppUpdates.checkNeedsUpdate({ country: 'it' }).then(result => { if (result.shouldUpdate) { const updateOptions: StartUpdateOptions = Platform.select({ ios: { title: 'Update available', message: "There is a new version of the app available on the App Store, do you want to update it?", buttonUpgradeText: 'Update', buttonCancelText: 'Cancel', country: 'it', // 👈🏻 the country code for the specific version to lookup for (optional) }, android: { updateType: IAUUpdateKind.IMMEDIATE, }, }); inAppUpdates.startUpdate(updateOptions); } }); ``` -------------------------------- ### IAUUpdateKind Enum Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/README.md Enum for specifying the type of in-app update on Android. ```APIDOC IAUUpdateKind: FLEXIBLE: 'flexible' IMMEDIATE: 'immediate' ``` -------------------------------- ### Remove Status Update Listener (Android) Source: https://github.com/sudoplz/sp-react-native-in-app-updates/blob/master/README.md Removes an existing listener that was previously added to track the status of in-app update downloads. This function is specific to Android. ```APIDOC removeStatusUpdateListener(callback: (status: StatusUpdateEvent) : void): void (Android only) Parameters: callback: (status: StatusUpdateEvent) : void - The callback function to remove. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.