With react-native-update-in-app library you can easily implement in-app updates in your React Native app using CDN or any other file server

Overview

React Native In-App update

With react-native-update-in-app library you can easily implement in-app updates in your React Native app using CDN or any other file server. In-app updates (like Google Play In-app updates) allows your app users to download and install update right in your app UI.

Example

It's best to see it with your own eyes 😉

git clone https://github.com/NepeinAV/react-native-update-in-app.git \
    && cd react-native-update-in-app

yarn
yarn example android

Installation

yarn add react-native-update-in-app

React Native should automatically link the library.

Usage

This library provides an API to download APK file and install it, but does not provide the UI (React Native developer should implement it by himself), because every app has its own unique design and requirements.

In typical use case you should follow these steps:

Step 1

Check that your app has an update. You can use whatever you want to send the request to the server and retrieve info. For example, you can use fetch to get update.json file and compare your app current version with server version:

import React, { useCallback, useState } from 'react';

import { AppUpdate } from 'react-native-update-in-app';

const [updateData, setUpdateData] = useState<{
    url: string;
    updateMessage: string;
} | null>(null);

<...>

const checkUpdate = useCallback(async () => {
    if (Platform.OS === 'ios') {
        Alert.alert('iOS is not supported');

        return false;
    }

    const result = await fetch(
        'https://raw.githubusercontent.com/NepeinAV/react-native-update-in-app/master/example/app-updates/update.json',
    );
    const data = await result.json();
    const currentVersionCode = await AppUpdate.getVersionCode();

    if (data.versionCode <= currentVersionCode) {
        Alert.alert('Update was not found');
    } else {
        setUpdateData(data);
    }
}, []);

<...>

Step 2

If your decide that your app needs update, then request library to download APK file like that:

AppUpdate.downloadApp(updateData.url);

AppUpdate.downloadApp method starts background service that will download your APK file. The APK continues to download even if the app in background state.

But how do you now when the file has been downloaded? The library API has event called onDownloadProgress, that you need to listen via AppUpdate.onDownloadProgress(). This event has four states: start, downloading, end and error. You can implement it like that:

import React, { useCallback, useState } from 'react';

import { AppUpdate } from 'react-native-update-in-app';

<...>

const [downloadProgress, setDownloadProgress] = useState(0);
const [isApkLoaded, setApkLoaded] = useState(false);
const [apkName, setApkName] = useState<string | null>(null);
const [isApkLoading, setDownloading] = useState(false);

<...>

AppUpdate.onDownloadProgress(async (event) => {
    if (event.status === 'start') {
        setDownloadProgress(0);
        setDownloading(true);
        setApkLoaded(false);
        setApkName(null);

        return;
    }

    if (event.status === 'downloading') {
        setDownloadProgress(event.progress);

        return;
    }

    if (event.status === 'end') {
        setDownloadProgress(100);
        setDownloading(false);

        setApkLoaded(true);
        setApkName(event.apkFileName);

        await AppUpdate.installApp(event.apkFileName);

        return;
    }

    if (event.status === 'error') {
        Alert.alert(event.errorMessage);

        setDownloadProgress(0);
        setDownloading(false);
        setApkLoaded(false);
        setApkName(null);

        return;
    }
});

<...>

Step 3

When your APK was downloaded you can install it. Just call this:

AppUpdate.installApp(apkName);

It will call system's default package installer with your APK file.

That's it! 😎

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

You might also like...

Tencent Kona JDK17 is a no-cost, production-ready distribution of the Open Java Development Kit (OpenJDK), Long-Term Support(LTS) with quarterly updates.

Tencent Kona JDK17 is a no-cost, production-ready distribution of the Open Java Development Kit (OpenJDK), Long-Term Support(LTS) with quarterly updates.

Tencent Kona JDK17 Tencent Kona JDK17 is a no-cost, production-ready distribution of the Open Java Development Kit (OpenJDK), Long-Term Support(LTS) w

Nov 30, 2022

Create your Java crypto trading bot in minutes. Our Spring boot starter takes care of exchange connections, accounts, orders, trades, and positions so you can focus on building your strategies.

Create your Java crypto trading bot in minutes. Our Spring boot starter takes care of exchange connections, accounts, orders, trades, and positions so you can focus on building your strategies.

Quick Start | Documentation | Discord | Twitter Create and run your java crypto trading bot in minutes Our Spring boot starter takes care of exchange

Jan 3, 2023

We have created a techblog website where a user can post technical posts and edit and update the post accordingly.

TechBlog Introduction - In this project we have created a technical blog website where we have provided functionalities such as 1) SignUp 2) Login 3)

Jan 23, 2022

Literally just adds milk, to act as a bridge for any other mods that want to do the same.

Milk lib Literally just adds milk, to act as a bridge for any other mods that want to do the same. See the Milk class for customisation; It allows for

Oct 17, 2022

Tinker is a hot-fix solution library for Android, it supports dex, library and resources update without reinstall apk.

Tinker is a hot-fix solution library for Android, it supports dex, library and resources update without reinstall apk.

Tinker Tinker is a hot-fix solution library for Android, it supports dex, library and resources update without reinstalling apk. Getting started Add t

Dec 30, 2022

A mod for OneConfig that allows you to customize the hit color of any living entity to your liking.

A mod for OneConfig that allows you to customize the hit color of any living entity to your liking.

HitColor A mod for OneConfig that allows you to customize the hit color of any living entity to your liking. Features An option to toggle Armor being

Nov 5, 2022

A minecraft minigame where you have to defend your bed and destroy the others. Once your bed is destroyed, you cannot respawn.

A minecraft minigame where you have to defend your bed and destroy the others. Once your bed is destroyed, you cannot respawn.

As from November 1st 2021 BedWars1058 by Andrei Dascălu becomes open source under GNU GPL 3.0 license. If you are a developer I would really appreciat

Dec 26, 2022

How To Implement Fault Tolerance In Microservices Using Resilience4j

springboot-resilience4j-demo How To Implement Fault Tolerance In Microservices Using Resilience4j? Things todo list: Clone this repository: git clone

Mar 30, 2022

This sample shows how to implement two-way text chat over Bluetooth between two Android devices, using all the fundamental Bluetooth API capabilities.

This sample shows how to implement two-way text chat over Bluetooth between two Android devices, using all the fundamental Bluetooth API capabilities.

Zenitsu-Bluetooth Chat Application This sample shows how to implement two-way text chat over Bluetooth between two Android devices, using all the fund

Jan 16, 2022
Releases(v1.0.1)
Owner
Nepein Andrey
Nepein Andrey
A minimalistic Face Recognition module which can be easily incorporated in any Android project.

Real Time Face Recognition with TfLite A minimalistic Face Recognition module which can be easily incorporated in any Android project. Key Features Fa

Abhinav Sharma 2 Jun 21, 2022
Classpy is a GUI tool for investigating Java class file, Lua binary chunk, Wasm binary code, and other binary file formats.

Classpy Classpy is a GUI tool for investigating Java class file, Lua binary chunk, Wasm binary code, and other binary file formats. Inspiration This t

null 1k Dec 17, 2022
This project uses the artificial potential field method to realize the path planning of the robot, and completes the trajectory optimization through other settings. It can also be combined with laser SLAM, target recognition and other technologies for path planning.

FRCAutoDriver 项目说明 Project Instruction 本项目利用人工势场法,实现机器人的路径规划,并通过其他设置完成轨迹优化,还可以结合激光SLAM、目标识别等技术进行路径规划 This project uses the artificial potential field

ZhangzrJerry 2 Sep 9, 2022
Facsimile - Copy Your Most Used Text to Clipboard Easily with Facsimile!. It Helps You to Store You Most Used Text as a Key, Value Pair and Copy it to Clipboard with a Shortcut.

Facsimile An exact copy of Your Information ! Report Bug · Request Feature Table of Contents About The Project Built With Getting Started Installation

Sri lakshmi kanthan P 1 Sep 12, 2022
Using this library, and writing a few lines of code, you can manage your own domain objects in ZooKeeper

Using this library, and writing a few lines of code, you can manage your own domain objects in ZooKeeper. It provides CRUD operations and change notifications out of the box.

Sahab 4 Oct 26, 2022
Sceneform React Native AR Component using ARCore and Google Filament as 3D engine. This the Sceneform Maintained Component for React Native

Discord Server Join us on Discord if you need a hand or just want to talk about Sceneform and AR. Features Remote and local assets Augmented Faces Clo

SceneView Open Community 42 Dec 17, 2022
This project was created as a simple example to show how we can implement the hexagonal architecture(software design) proposed by Netflix.

Netflix Hexagonal Architecture Table of contents About the project Description Built with Installation Requirements to run Usage information Run Licen

José Lucas 12 Dec 20, 2022
Tuya 37 Dec 26, 2022
💡极致性能的企业级Java服务器框架,RPC,游戏服务器框架,web应用服务器框架。(Extreme fast enterprise Java server framework, can be RPC, game server framework, web server framework.)

?? 为性能而生的万能服务器框架 ?? Ⅰ. zfoo简介 ?? 性能炸裂,天生异步,Actor设计思想,无锁化设计,基于Spring的MVC式用法的万能RPC框架 极致序列化,原生集成的目前二进制序列化和反序列化速度最快的 zfoo protocol 作为网络通讯协议 高可拓展性,单台服务器部署,

null 1k Jan 1, 2023
Welcome to the EHS robotics club's GitHub repository, this will also be used as our primary community center and means of communication. Also be sure to join our remind for on the go updates @EHSFTC21

NOTICE This repository contains the public FTC SDK for the Ultimate Goal (2020-2021) competition season. Formerly this software project was hosted her

null 5 Feb 25, 2022