剛剛學(xué)不久React羽嫡,感覺(jué)還行(僅憑個(gè)人喜好)自己做了一下熱跟新跟同學(xué)們分享一下肩袍,前提你的工具已經(jīng)配置好了,去中文網(wǎng)配置一下? ?ok(這里只講iOS的 ?) 磨刀霍霍向豬羊
一颜屠,React Native 之熱更新
1. 用終端下載codePush ??npm install -g code-push-cli
2. 注冊(cè)一下 用命令 ?code-push register ? ? ?授權(quán)一般選擇Github 就行(沒(méi)有注冊(cè)一下)code-push logout 是退出命令(只要不退出一直保持登錄)
3. ?添加項(xiàng)目名稱?code-push app add AppName ?AppName ?以后用這個(gè)APP名字更新代碼 ? ?返回deployment key ?這個(gè)后面有用
4. 添加依賴 npm install —save react-native-code-push 并去庫(kù)里查看一下
5.添加關(guān)聯(lián) react-native link.? info文件中會(huì)有一個(gè)codePushdeploymentkey? ?
6 添加設(shè)置iOS
下面可以通過(guò)code-push deployment ls appName -k 查看key 并填入
7重點(diǎn)熱更新
? 自動(dòng)更新在APP.js.文件里 找到 componentDidMount(){} 往里面添加? codePush密浑。sync({
? ? ? updateDialog: {
? ? ? ? appendReleaseDescription: true,
? ? ? ? descriptionPrefix:'\n\n更新內(nèi)容:\n',
? ? ? ? title:'更新',
? ? ? ? mandatoryUpdateMessage:'',
? ? ? ? mandatoryContinueButtonLabel:'更新',
? ? ? },
? ? ? mandatoryInstallMode:codePush.InstallMode.IMMEDIATE,
})。
mandatoryInstallMode 這個(gè)更新方式有三四中注意下這里是強(qiáng)制跟新
手動(dòng)更新
codePush.checkForUpdate().then((update) => {
? ? if (!update) {
? ? ? ? Alert.alert("提示", "已是最新版本--", [
? ? ? ? ? ? {
? ? ? ? ? ? ? ? text: "Ok", onPress: () => {
? ? ? ? ? ? ? ? ? ? console.log("點(diǎn)了OK");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ]);
? ? } else {
? ? ? ? codePush.sync({
? ? ? ? ? ? ? ? updateDialog: {
? ? ? ? ? ? ? ? ? ? appendReleaseDescription: true,
? ? ? ? ? ? ? ? ? ? descriptionPrefix:'更新內(nèi)容',
? ? ? ? ? ? ? ? ? ? title:'更新',
? ? ? ? ? ? ? ? ? ? mandatoryContinueButtonLabel:'更新',
? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? mandatoryInstallMode: codePush.InstallMode.IMMEDIATE,
? ? ? ? ? ? },
? ? ? ? ? ? (progress) => {
? ? ? ? ? ? ? ? console.log(progress.receivedBytes + " of " + progress.totalBytes + " received.");
? ? ? ? ? ? }
? ? ? ? );
? ? }
})
8.打包跟新 code-push release-react MyApp-iOS ios? --t 1.0.0 --dev false --d Production --des "1.優(yōu)化操作流程" --m true ? ? ?(這里的1.0.0 跟iOS版本號(hào)一致街图,iOS才能熱跟新)
ok iOS 可以熱跟新懒构,不要給提示框就行