react-native-hotpatch-ota
v0.1.0
Published
The official React Native SDK for HotPatch OTA updates. Ship critical fixes bypassing app stores.
Maintainers
Readme
react-native-hotpatch-ota
The official React Native SDK for HotPatch — an open-source, self-hosted Over-The-Air (OTA) update platform. Ship critical bug fixes and features directly to your users' devices, bypassing app store review wait times.
🚀 Features
- Instant Delivery: Push updates to your JavaScript bundle instantly.
- Secure: All updates are secured with Ed25519 cryptographic signatures and AES-256 encryption.
- Rollout Control: Deploy to 10%, 50%, or 100% of your users.
- Channels: Segment users into
production,staging, orbetachannels. - Automatic Rollbacks: If an update causes a crash on launch, HotPatch automatically rolls back to the previous working version.
📦 Installation
npm install react-native-hotpatch-ota
# or
yarn add react-native-hotpatch-ota⚙️ Native Integration
HotPatch requires a tiny bit of native code configuration to intercept the JS bundle loading process.
Android
- Update
MainApplication.kt(orMainActivity.ktdepending on your RN version):
import com.hotpatch.OTAPackage
import com.hotpatch.OTAUpdateManager
class MainApplication : Application(), ReactApplication {
// ...
override fun getJSBundleFile(): String? {
// This will load the downloaded bundle if an update exists, otherwise fall back to the assets bundle
return OTAUpdateManager.getBundlePath(this)
}
}iOS
- Update
AppDelegate.swift:
import rn_ota_sdk
@objc class AppDelegate: RCTAppDelegate {
override func sourceURL(for bridge: RCTBridge!) -> URL? {
return OTAUpdateManager.shared.getBundleURL() ?? super.sourceURL(for: bridge)
}
}🛠 Usage
Initialization
Add this to your app's entry file (e.g., App.tsx or index.js):
import { HotPatch } from 'react-native-hotpatch-ota';
// Initialize the SDK early in your app lifecycle
HotPatch.init({
appKey: 'YOUR_APP_KEY', // Get this from your HotPatch Dashboard
publicKey: 'YOUR_PUBLIC_KEY', // Generated via the HotPatch CLI
channel: 'production', // e.g., 'production', 'staging', 'beta'
checkOnLaunch: true // Automatically check for updates on startup
});Manual Checks
If you prefer to check for updates manually (e.g., behind a button or a custom UI):
import { HotPatch } from 'react-native-hotpatch-ota';
async function checkAndUpdate() {
const update = await HotPatch.checkForUpdate();
if (update?.updateAvailable) {
console.log('Update found! Downloading...');
await HotPatch.applyUpdate(update);
console.log('Update applied. It will run on the next app restart.');
} else {
console.log('App is up to date.');
}
}📚 Publishing Updates
Updates are published using the HotPatch CLI.
# 1. Install the CLI
cargo install hotpatch-cli
# or download from your dashboard
# 2. Login to your server
hotpatch login
# 3. Publish a new update
hotpatch release --platform android --version 1.0.1 --channel production🛡 Security Note
Your YOUR_PUBLIC_KEY is completely safe to embed in your React Native app. It is only used to verify that downloaded updates were signed by your private key. Never embed or commit your private signing key.
Built with ❤️ by the HotPatch Team.
