react-native-codepush
, cho phép bạn tự chủ hoàn toàn trong việc cập nhật ứng dụng React Native qua OTA. Thay vì phải gửi ứng dụng lên App Store hay Google Play để phê duyệt, Hot Updater giúp bạn cập nhật ngay lập tức JavaScript bundle, mang đến tốc độ triển khai cực nhanh.Bước | Mô Tả Chi Tiết |
---|---|
1 | Tạo bucket S3 cho lưu trữ bundle |
2 | Thiết lập Lambda@Edge function |
3 | Cấu hình CloudFront phân phối nội dung |
4 | Cấp quyền IAM hợp lý cho các dịch vụ |
<mark>Lưu ý:</mark> Không chỉnh sửa hoặc xóa các đoạn mã tự động tạo để đảm bảo tính ổn định của hệ thống. Điều này đặc biệt quan trọng khi sử dụng các công cụ như react-native-config
để quản lý nhiều môi trường.
fingerprint.json
với nội dung mẫu:yarn && cd ios && pod install && cd ..
App.tsx
theo mẫu chính thức: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', 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', // or "appVersion" }), requestHeaders: { // Thêm header tùy chỉnh 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" }}
yarn channel_update_production && yarn update_android_prod
yarn hot-updater-console
yarn fingerprint_update