New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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

  • 0.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

sp-react-native-in-app-updates

Getting started

Installation

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

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

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, and react-native-siren on iOS.

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

Methods:

checkNeedsUpdate(checkOptions: CheckOptions) : CheckResult

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 CheckResult:

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: UpdateOptions) : Promise

Where: UpdateOptions

OptionTypeDescription
updateType (Android ONLY)(required on Android) intEither SpInAppUpdates.UPDATE_TYPE.FLEXIBLE or SpInAppUpdates.UPDATE_TYPE.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)

##Example:

import SpInAppUpdates from 'sp-react-native-in-app-updates';

const inAppUpdates = new SpInAppUpdates();

inAppUpdates.checkNeedsUpdate({
  curVersion: '4.8.8',
  toSemverConverter: (ver => {
    // i.e if 400401 is the Android version, and we want to convert it to 4.4.1
    const androidVersionNo = parseInt(ver, 10);
    const majorVer = Math.trunc(androidVersionNo / 10000);
    const minorVerStarter = androidVersionNo - majorVer * 10000;
    const minorVer = Math.trunc(minorVerStarter / 100);
    const patchVersion = Math.trunc(minorVerStarter - minorVer * 100);
    return `${majorVer}.${minorVer}.${patchVersion}`;
  })
}).then(result => {
  if (result.shouldUpdate) {
	  inAppUpdates.startUpdate({
	    updateType: SpInAppUpdates.UPDATE_TYPE.FLEXIBLE // android only, on iOS the user will be promped to go to your app store page
	  })
  }
})

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 2020

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