Gathering detailed insights and metrics for sp-react-native-in-app-updates
Gathering detailed insights and metrics for sp-react-native-in-app-updates
Gathering detailed insights and metrics for sp-react-native-in-app-updates
Gathering detailed insights and metrics for sp-react-native-in-app-updates
npm install sp-react-native-in-app-updates
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
491 Stars
159 Commits
66 Forks
6 Watching
12 Branches
17 Contributors
Updated on 20 Nov 2024
TypeScript (54.44%)
Java (25.31%)
Kotlin (5.76%)
Objective-C (5.11%)
Ruby (4.38%)
JavaScript (2.28%)
Objective-C++ (1.81%)
Shell (0.91%)
Cumulative downloads
Total Downloads
Last day
-11.4%
2,245
Compared to previous day
Last week
8.8%
13,808
Compared to previous week
Last month
4.9%
58,059
Compared to previous month
Last year
22.7%
590,219
Compared to previous year
2
21
This is a react-native native module that works on both iOS and Android, and checks the stores (play/app) for a new version of your app and can prompt your user for an update.
It uses embedded in-app-updates via Play-Core on Android (to check & download google play patches natively from within the app), and react-native-siren on iOS (to check & navigate the user to the AppStore).
Because to this day I'm not aware of any react-native libraries that use play core to offer embedded in-app-updates besides this one
$ npm install sp-react-native-in-app-updates --save
On React Native iOS you may need to also add the following lines in your Info.plist to be able to launch the store deep link.
<key>LSApplicationQueriesSchemes</key>
<array>
<string>itms-apps</string>
</array>
For Expo Apps Add the following to your expo app.json
or app.config.json
.
"ios": {
"infoPlist": {
"LSApplicationQueriesSchemes": ["itms-apps"]
}
},
Next, rebuild the native files using npx expo prebuild --clean && eas build -p ios
This project uses react-native-device-info
in the background. Install it to ensure everything works correctly.
In order to make it work using Expo you need to replace react-native-device-info dependency.
react-native-device-info.js
file in root with following content. Requires expo-constants dependency. If you target iOS then you also need to ensure you add a bundleIdentifier to the ios section of your expo config.1import Constants from "expo-constants" 2 3export const getBundleId = () => { 4 return Constants.expoConfig?.ios?.bundleIdentifier ?? ''; 5} 6export const getVersion = () => { 7 return Constants.expoConfig?.version 8} 9export default { 10 getBundleId, 11 getVersion, 12};
1plugins: [ 2 [ 3 'module-resolver', 4 { 5 root: ['.'], 6 alias: { 7 'react-native-device-info': './react-native-device-info.js' 8 } 9 } 10 ], 11 ... 12]
1import SpInAppUpdates, { 2 NeedsUpdateResponse, 3 IAUUpdateKind, 4 StartUpdateOptions, 5} from 'sp-react-native-in-app-updates'; 6 7const inAppUpdates = new SpInAppUpdates( 8 false // isDebug 9); 10// curVersion is optional if you don't provide it will automatically take from the app using react-native-device-info 11inAppUpdates.checkNeedsUpdate({ curVersion: '0.0.8' }).then((result) => { 12 if (result.shouldUpdate) { 13 let updateOptions: StartUpdateOptions = {}; 14 if (Platform.OS === 'android') { 15 // android only, on iOS the user will be promped to go to your app store page 16 updateOptions = { 17 updateType: IAUUpdateKind.FLEXIBLE, 18 }; 19 } 20 inAppUpdates.startUpdate(updateOptions); // https://github.com/SudoPlz/sp-react-native-in-app-updates/blob/master/src/types.ts#L78 21 } 22});
1// 👇🏻 (optional) 2inAppUpdates.checkNeedsUpdate({ country: 'it' }).then(result => { 3 if (result.shouldUpdate) { 4 const updateOptions: StartUpdateOptions = Platform.select({ 5 ios: { 6 title: 'Update available', 7 message: "There is a new version of the app available on the App Store, do you want to update it?", 8 buttonUpgradeText: 'Update', 9 buttonCancelText: 'Cancel', 10 country: 'it', // 👈🏻 the country code for the specific version to lookup for (optional) 11 }, 12 android: { 13 updateType: IAUUpdateKind.IMMEDIATE, 14 }, 15 }); 16 inAppUpdates.startUpdate(updateOptions); 17 } 18});
checkNeedsUpdate(checkOptions: CheckOptions) : Promise<NeedsUpdateResponse>
Checks if there are any updates available.
Where:
CheckOptions
Options | Type | Description |
---|---|---|
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 (iOS only) | (optional) String | default undefined , it will filter by country code while requesting an update, The value should be ISO 3166-1 country code |
and NeedsUpdateResponse
:
Result | Type | Description |
---|---|---|
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) |
startUpdate(updateOptions: StartUpdateOptions) : Promise
Shows pop-up asking user if they want to update, giving them the option to download said update.
Where:
StartUpdateOptions
Option | Type | Description |
---|---|---|
updateType (Android ONLY) | (required on Android) IAUUpdateKind | 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 | The title of the alert prompt when there's a new version. (default: Update Available ) |
message (iOS only) | (optional) String | 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 | The text of the confirmation button on the alert prompt (default: Upgrade ) |
buttonCancelText (iOS only) | (optional) String | The text of the cancelation button on the alert prompt (default: Cancel ) |
forceUpgrade (iOS only) | (optional) Boolean | If set to true the user won't be able to cancel the upgrade (default: false ) |
bundleId (iOS only) | (optional) String | 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 | 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<IosStartUpdateOptionWithLocalVersion> | An array of IosStartUpdateOptionWithLocalVersion that specify rules dynamically based on what version the device is currently running. (default: undefined ) |
installUpdate() : void
(Android only)Installs a downloaded update.
addStatusUpdateListener(callback: (status: StatusUpdateEvent) : void) : void
(Android only)Adds a listener for tracking the current status of the update download.
Where: StatusUpdateEvent
Option | Type | Description |
---|---|---|
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 |
removeStatusUpdateListener(callback: (status: StatusUpdateEvent) : void): void
(Android only)Removes an existing download status listener.
Debugging in-app-updates is tricky, so arm yourself with patience, enable debug logs by passing true to our library constructor. To enable console.log
for release you may need react-native log-android
or react-native log-ios
.
First of all use a REAL device.
(you don't like the debug variant right? Neither do we, but we couldn't find an easier way to check that everything's working fine - debug builds don't work with in-app-updates unfortunately)
This is what you'd be updating to
Make sure that the button within that link says UPDATE (and NOT install)
That means google play knows there's an available update
Haven't really found any easier ways to test that everything works, but hey.. it get's the job done
Keep in mind that this library is JUST a WRAPPER of the in-app-update api, so if you have trouble making in-app-updates work it's most probably because you're doing something wrong with google play.
Important: If the app you are testing doesn’t appear with an available update, don't bother checking for updates programmatically, because you'll probably never see any available updates via code either.
This library is offered as is, if you'd like to change something please open a PR
Read the CHANGELOG.md file
MIT
No vulnerabilities found.
Reason
license file detected
Details
Reason
binaries present in source code
Details
Reason
Found 8/15 approved changesets -- score normalized to 5
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
24 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More