Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sp-react-native-in-app-updates

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sp-react-native-in-app-updates

Handles Android native updates in app by using play-core

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
15K
decreased by-5.32%
Maintainers
1
Weekly downloads
 
Created
Source

sp-react-native-in-app-updates

In app update example

Getting started


What is this?

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).

Why?

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


Installation

$ npm install sp-react-native-in-app-updates --save


iOS only:

On 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>

Usage

import SpInAppUpdates, {
  NeedsUpdateResponse,
  IAUUpdateKind,
  StartUpdateOptions,
} from 'sp-react-native-in-app-updates';

const inAppUpdates = new SpInAppUpdates(
  false // isDebug
);

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)
  }
});


Methods:


checkNeedsUpdate(checkOptions: CheckOptions) : Promise<NeedsUpdateResponse>

Checks if there are any updates available.

Where: CheckOptions

OptionsTypeDescription
curVersion(required) StringThe semver of your current app version
toSemverConverter(optional) FunctionThis 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) FunctionBy 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

and NeedsUpdateResponse:

ResultTypeDescription
shouldUpdateBooleanWether there's a newer version on the store or not
storeVersionStringThe latest app/play store version we're aware of
otherObjectOther info returned from the store (differs on Android/iOS)

startUpdate(checkOptions: StartUpdateOptions) : Promise

Shows pop-up asking user if they want to update, giving them the option to download said update.

Where: StartUpdateOptions

OptionTypeDescription
updateType (Android ONLY)(required on Android) IAUUpdateKindEither IAUUpdateKind.FLEXIBLE or IAUUpdateKind.IMMEDIATE. This uses play-core below the hood, read more here about the two modes.
title (iOS only)(optional) StringThe title of the alert prompt when there's a new version. (default: Update Available)
message (iOS only)(optional) StringThe 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) StringThe text of the confirmation button on the alert prompt (default: Upgrade )
buttonCancelText (iOS only)(optional) StringThe text of the cancelation button on the alert prompt (default: Cancel)
forceUpgrade (iOS only)(optional) BooleanIf set to true the user won't be able to cancel the upgrade (default: false)

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

OptionTypeDescription
statusInstallationStatusThe status of the installation (https://developer.android.com/reference/com/google/android/play/core/install/model/InstallStatus)
bytesDownloadedintHow many bytes were already downloaded
totalBytesToDownloadintThe total amount of bytes in the update

removeStatusUpdateListener(callback: (status: StatusUpdateEvent) : void): void (Android only)

Removes an existing download status listener.

Example:

Example project

Troubleshooting

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.

Common issues:

  • You're getting a ERROR_API_NOT_AVAILABLE error: Probably because you're attempting to test in-app-updates on debug. You'll need to use internal app sharing in order to debug (Read more: https://stackoverflow.com/a/59456561/1658268).

  • The minimum API SDK for android to support in-app-updates is 21

  • Your play store version or play services is out of date

Debugging is tricky, so arm yourself with patience, enable debug logs by passing true to the constructor of


Contributing:

This library is offered as is, if you'd like to change something please open a PR


License

MIT

Keywords

FAQs

Package last updated on 13 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc