react-native-codepush
, cung cấp khả năng cập nhật Over-The-Air cho các ứng dụng React Native. Điểm đặc biệt của Hot Updater là cho phép bạn tự kiểm soát cơ sở hạ tầng cập nhật và dữ liệu, không phải lệ thuộc vào dịch vụ bên thứ ba.File | Mục đích |
---|---|
.env | Chứa các biến môi trường liên quan AWS |
hot-updater.config.ts | Cấu hình chính cho Hot Updater |
Lưu ý: Không chỉnh sửa các phần code tự động tạo để đảm bảo hoạt động ổn định, đặc biệt khi dùng nhiều scheme hoặc flavor trong React Native.
fingerprint.json
ở thư mục gốc dự án với nội dung:yarn && cd ios && pod install && cd ..
import { getUpdateSource, HotUpdater } from '@hot-updater/react-native';import React from 'react';import { Text, View } from 'react-native';import Config from 'react-native-config';
const App = () => { return ( <View style={{ flex: 1, backgroundColor: 'teal', // Thử đổi "pink" để kiểm tra cập nhật justifyContent: 'center', alignItems: 'center', }} > <Text>{Config.env}-- 555</Text> <Text>{__DEV__ ? 'Development Mode' : 'Release Mode'}</Text> <Text>Fingerprint: {HotUpdater.getFingerprintHash()}</Text> <Text>Channel: {HotUpdater.getChannel()}</Text> <Text>App Version: {HotUpdater.getAppVersion()}</Text> <Text>Bundle Id: {HotUpdater.getBundleId()}</Text> <Text>Min Bundle Id: {HotUpdater.getMinBundleId()}</Text> </View> );};
export default HotUpdater.wrap( { source: getUpdateSource('https://do1f2fjq14bee.cloudfront.net/api/check-update', { updateStrategy: 'fingerprint', // hoặc 'appVersion' }), requestHeaders: { // Thêm header tùy ý nếu cần }, fallbackComponent: ({ progress, status }) => ( <View style={{ flex: 1, padding: 20, borderRadius: 10, justifyContent: 'center', alignItems: 'center', backgroundColor: 'rgba(0, 0, 0, 0.5)', }} > <Text style={{ color: 'white', fontSize: 20, fontWeight: 'bold' }}> {status === 'UPDATING' ? 'Updating...' : 'Checking for Update...'} </Text> {progress > 0 ? ( <Text style={{ color: 'white', fontSize: 20, fontWeight: 'bold' }}>{Math.round(progress * 100)}%</Text> ) : null} </View> ), }, App);
package.json
:{ "scripts": { "setDevelopment": "ENVFILE=.env.development", "setStaging": "ENVFILE=.env.staging", "setProduction": "ENVFILE=.env.production", "aos:dev-release": "yarn setDevelopment && react-native run-android --mode=developmentrelease", "aos:prod-release": "yarn setProduction && react-native run-android --mode=productionrelease", "hot-updater-console": "yarn hot-updater console", "check_fingerprint_hash": "yarn hot-updater fingerprint", "fingerprint_update": "yarn hot-updater fingerprint create", "channel_update_production": "yarn hot-updater channel set production", "channel_update_development": "yarn hot-updater channel set development", "update_ios_dev": "yarn installAll && yarn setDevelopment && npx hot-updater deploy -p ios -c development -f", "update_ios_prod": "yarn installAll && yarn setProduction && npx hot-updater deploy -p ios -c production -f", "update_android_dev": "yarn channel_update_development && yarn setDevelopment && npx hot-updater deploy -p android -c development -f", "update_android_prod": "yarn channel_update_production && yarn setProduction && npx hot-updater deploy -p android -c production -f" }}
--target-app-version
.Lỗi thường gặp:
Fingerprint mismatch. 'hot-updater fingerprint create' to update fingerprint.json
yarn fingerprint_update
yarn hot-updater-console