react-native-code-push 熱更新的使用發(fā)布- iOS和Android

code push 運(yùn)作模式說明:

RN的熱更有ios 的熱更和android的熱更,兩者互不相干,iOS 有Staging 和 Release(Production) 兩種 deploymentKey ,Android同理也有兩種key,這個(gè)key是你將app添加到服務(wù)器的時(shí)候自動(dòng)下發(fā)給你的(下面會(huì)說),這是用來識(shí)別你在服務(wù)器中app key的唯一值。
即:


圖片.png

在RN端推的都是JS和靜態(tài)文件(例如圖片、icon)到服務(wù)器,這個(gè)服務(wù)器可以是自建服務(wù)器也可以是微軟的服務(wù)器,因公司使用的是自建服務(wù)器,所以以自建服務(wù)器的來說。

利用code push 的指令將需要更新的js和靜態(tài)文件推送到服務(wù)器。
在app打開的時(shí)候,就會(huì)詢問這個(gè)服務(wù)是否有更新,有的話就可以選擇把更新過的js和靜態(tài)文件下載下來,即完成更新,如果是有添加了第三方庫或者是有修改到原生Java或ios的原生代碼的時(shí)候,就需要重新打包更新app,要上架的話就要重新審核。

放上參考鏈接:
http://m.itdecent.cn/p/75eabb0d098a
http://m.itdecent.cn/p/be4040d5aff7

步驟:

1、安裝code-push-cli

npm install -g code-push-cli

code-push -v 查看驗(yàn)證

2、注冊(cè)(登錄)賬號(hào)

code-push login
code-push register
圖片.png

3、往服務(wù)器里添加新的android app 和 iOS app

code-push app add <appName> android react-native 
code-push app add <appName> ios react-native 
執(zhí)行這兩個(gè)指令后會(huì)返回上述的兩個(gè)系統(tǒng)平臺(tái)的Production、Staging 的 deploymentKey
//例:
code-push app add phonePlayer-android android react-native
code-push app add phonePlayer-ios ios react-native

4、執(zhí)行完后可以查看服務(wù)器里面是否能看到剛才已添加的app

code push ls (或list)


圖片.png

5、app安裝react-native-native-code-push第三方庫

根據(jù)官網(wǎng)的步驟安裝了react-native-code-push 后配置給android和iOS配置一下 測(cè)試版的 熱更和 發(fā)布正式版的熱更 deploymentKey ,到時(shí)候別人安裝的是Staging 版的,用戶就只能下載更新你推到Staging版的js和靜態(tài)文件,安裝release(即Production)版的,用戶就只能更新發(fā)布版的。

android:
(1)、在android/app/build.gradle



android {
    ...
    buildTypes {
        debug {
            ...
            // Note: CodePush updates should not be tested in Debug mode as they are overriden by the RN packager. However, because CodePush checks for updates in all modes, we must supply a key.
            resValue "string", "CodePushDeploymentKey", '""'
            ...
        }

        releaseStaging {
            ...
            resValue "string", "CodePushDeploymentKey", '"插入Staging的DeploymentKey"'

            // Note: It is a good idea to provide matchingFallbacks for the new buildType you create to prevent build issues
            // Add the following line if not already there
            matchingFallbacks = ['release']
            ...
        }

        release {
            ...
            resValue "string", "CodePushDeploymentKey", '"插入Production的DeploymentKey"'
            ...
        }
    }
    ...
}

(2)、在/android/app/src/main/res/values/strings.xml文件中添加服務(wù)器的地址

<resources>
    ...
    <string name="CodePushServerURL">https://xxx.xxx.com/</string>
    ...
</resources>

iOS:

(1)iOS的根據(jù)官網(wǎng)的multi-deployment-testing-ios.md配置一下,添加Staging環(huán)境,到時(shí)候打包的時(shí)候可以選擇Staging或release打包。
(2)配置完后在info.plist里面添加服務(wù)器

    <key>CodePushDeploymentKey</key>
    <string>$(CODEPUSH_KEY)</string>
    <key>CodePushServerURL</key>
    <string>https://xxx.xxx.com/</string>

6、將打包更改過的文件推送到服務(wù)器

code-push release-react phonePlayer-android android -t 1.0.31 -m -d Staging --des "更改測(cè)試"
code-push release-react phonePlayer-ios ios -t 1.2.1 -m -d Staging --des "更改測(cè)試"

注:加 -m 是強(qiáng)制更新,不加則是可稍后更新。 Staging 是測(cè)試版,發(fā)布版的是Production。

6、在項(xiàng)目里面用

你傳入的是哪個(gè)的deploymentKey,就會(huì)詢問的是哪個(gè)是否有更新


圖片.png

那么此時(shí)你就可以使用

code-push deployment history appName Staging

來查看你發(fā)布的歷史
更多指令如下:

    code-push register    注冊(cè)賬號(hào)
    code-push login    進(jìn)行身份驗(yàn)證以開始管理您的應(yīng)用
    code-push logout    注銷當(dāng)前會(huì)話
    code-push access-key     查看和管理與您的帳戶關(guān)聯(lián)的訪問密鑰
    code-push access-key ls    列出登陸的token
    code-push access-key rm <accessKye> 刪除某個(gè) access-key

    // 管理App相關(guān)指令
    code-push app                        查看和管理您的CodePush應(yīng)用
    code-push app add phonePlayer-android android react-native                    在賬號(hào)里面添加一個(gè)新的app
    code-push app remove 或者 rm           在賬號(hào)里移除一個(gè)app
    code-push app rename                 重命名一個(gè)存在app
    code-push app list 或則 ls             列出賬號(hào)下面的所有app
    code-push app transfer               把a(bǔ)pp的所有權(quán)轉(zhuǎn)移到另外一個(gè)賬號(hào)

    // 查看deployment key
    code-push deployment add appName deploymentName  部署一個(gè)環(huán)境
    code-push deployment rm appName          刪除部署
    code-push deployment                     查看和管理您的應(yīng)用程序部署
    code-push deployment ls appName          列出應(yīng)用的部署
    code-push deployment ls appName -k       查看查詢部署環(huán)境的key
    code-push deployment history appName Staging

    // 其他
    code-push collaborator               查看和管理應(yīng)用協(xié)作者
    code-push debug                      查看正在運(yùn)行的應(yīng)用程序的CodePush調(diào)試日志
    code-push link                       將其他身份驗(yàn)證提供程序(例如GitHub)鏈接到現(xiàn)有的Mobile Center帳戶
    code-push patch                      更新現(xiàn)有版本的元數(shù)據(jù)
    code-push promote                    將最新版本從一種應(yīng)用程序部署升級(jí)到另一種
    code-push release                    發(fā)布更新到應(yīng)用程序部署
    code-push release-cordova            將Cordova更新發(fā)布到應(yīng)用程序部署
    code-push release-react              將React Native更新發(fā)布到應(yīng)用程序部署
    code-push rollback appName Production|Staging -t Label          回滾最新版本的應(yīng)用程序部署(Label你可以使用查看發(fā)布?xì)v史里面,v1、v2、v3等,即你要回滾的版本)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容