蒲公英自动更新版本管理以及更新后展示引导图

/**
* 获取存储的版本号
* @currentVersion 当前app版本
* 线上版本>当前版本 --跟新APP
* 引导图 @version老版本 存储的版本<更新的版本,则APP更新过 新版本展示showViewpager
*/

插件:react-native-device-info

    // 检查是否有新版本
    checkNewVersion(currentVersion,downloadNewVersion) {
        // 查看是否更新
        var url = 'https://www.pgyer.com/apiv2/app/check?_api_key=xxxxx&appKey=xxxxx';


        _fetch(fetch(url,{
            method: "POST",
            headers: {
                'Accept': 'application/json, text/plain, */*',
                "Content-Type": "application/json;charset=UTF-8"
            }
        }) ,8000 )
            .then(res => {
                if (res.ok) {
                    res.json().then(function(responseJson) {
                        console.log('是否有更新 -->',responseJson,currentVersion,);
                        if (responseJson.data.buildVersion > currentVersion) {
                            Alert.alert(
                                '提示',
                                '发现了新版本',
                                [
                                    {text:'立即更新',onPress:()=>downloadNewVersion(responseJson.data.downloadURL)}
                                ],
                                { cancelable: false }
                            )
                        }
                    })
                }
            })
  }
  downloadNewVersion(url) {
       console.log('下载页面 --> ',url);
       Linking.canOpenURL(url)
           .then(supported => {
               if (supported) {
                   return Linking.openURL(url);
               } else {
                   Alert.alert('提示','无法打开页面');
               }
           })
   }

 二:更新后引导图,

1. 先存储之前的版本

2. 比对更新后的版本

oldVersion<newVersion 则展示

 

posted @ 2019-07-01 11:18  谢玉胜  阅读(788)  评论(0编辑  收藏  举报
@allenXieyusheng