npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-update-app

v1.1.11

Published

react native app硬更新升级,兼容 android 和 ios

Downloads

16

Readme

react-native-update-app

全自动 app 硬更新组件,简单易用。

例子

example

预览

功能

  • Android点击升级按钮全自动升级安装apk,本地已下载了apk不会重新下载
  • IOS点击升级按钮进入苹果商店下载
  • 支持多主题(正在开发中...),及自定义主题

安装

因为该库依赖react-native-fs,所以首先需要安装它。具体点击查看react-native-fs

安装npm

npm install react-native-update-app --save

自动链接

react-native link react-native-update-app

成功后,命令行窗口会有 success 字样提示。但是这里有个坑,有时它不会自动往android/app/build.gradle里加入下面这句,需要手动加上。

dependencies {
    ...
    compile project(':react-native-update-app')  // 添加这句
}

当然如果你的代码里已经有上面一句了,就不需要添加了。

手动链接

如果自动成功,则忽略这一步。如果自动链接不行,请安装下面步骤进行手动链接。

iOS

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-update-app and add RNUpdateApp.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNUpdateApp.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)<

Android

  1. 打开 android/app/src/main/java/[...]/MainActivity.java
  • 添加 import com.reactlibrary.RNUpdateAppPackage;
  • getPackages()方法里添加 new RNUpdateAppPackage()
  1. android/settings.gradle 加入:
include ':react-native-update-app'
project(':react-native-update-app').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-update-app/android')
  1. android/app/build.gradle 里加入:
dependencies {
    ...
    compile project(':react-native-update-app')
}

注意

在主程序android/app/src/main/AndroidManifest.xml里增加下面代码。

<application ..>
...
        // 增加下面代码
    <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:grantUriPermissions="true"
            tools:replace="android:authorities"
            android:exported="false">
        <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                tools:replace="android:resource"
                android:resource="@xml/provider_paths"/>
    </provider>
</application>

使用

全自动检查版本进行更新升级,只需在app的入口文件中引入组件即可。

import RNUpdate from "react-native-update-app"

class App extends Component{
    // url 表示接口地址,在下面有详细介绍
    onBeforeStart = async ()=>{
        // 在这里可以发请求,用promise返回结果
        let res = await toolApi.updateApp() 
        return res.data
        /*返回结果 res 如下
        {
            "data": {
                "version":"1.1",
                "filename":"微信.apk",
                "url":"http://gdown.baidu.com/data/wisegame/785f37df5d72c409/weixin_1320.apk",
                "desc":["更新了一些bug", "修复了一些UI问题"]
            },
            "error":{"code":0}
        }*/
    }

    render() {
        return (
            <View>
                <RNUpdate
                    onBeforeStart={this.onBeforeStart}
                    progressBarColor="#f50"
                    updateBoxWidth={250},      // 选填,升级框的宽度
                    updateBoxHeight={250}      // 选填,升级框的高度
                    updateBtnHeight={38}       // 选填,升级按钮的高度
                    bannerImage={require('./imgs/a.png')}  // 选填,换升级弹框图片
                />
            </View>
        )
    }
}

onBeforeStart函数返回一个RNUpdate组件的配置对象。格式如上代码所示。

  • version: app 版本号(android/app/build.gradleversionName字段),,如果大于当前版本号,则会弹出更新框
  • url : 如果是android,返回 android apk 下载地址,如果是ios,返回 ios应用商店的对应 url。(根据上面的platform字段区分)
  • fileName: apk 文件名
  • desc: 更新说明

如果需要在其他地方调用,可以使用下面代码。

<RNUpdate ref={r=>global.$RNUpdate = r} />

async ()=>{
    let res = await toolApi.updateApp() 
    $RNUpdate.updateApp(res.data)
}

注意事项

  1. react-native-fs获取文件大小时,是根据请求头的Content-Length获取的。如果获取错误,则需要后端修改。