React Native SDK for SwiftPatch OTA updates with differential patching, automatic rollback, and bundle signing
npm install @swiftpatch/react-native



Over-the-Air (OTA) update SDK for React Native with differential patching, automatic rollback, and cryptographic verification. Optimized for the React Native New Architecture.
- ๐ Differential Patching - Download only what changed (bsdiff/bspatch)
- ๐ Automatic Rollback - Crash detection with instant recovery
- ๐ Bundle Signing - RSA signature verification for security
- โก New Architecture - TurboModules for 40% faster performance
- ๐ฏ Dual-Slot System - Safe production/staging environment switching
- ๐ฆ Small Updates - Patches typically 10-50x smaller than full bundles
- ๐ก๏ธ Type-Safe - Full TypeScript support
- ๐จ React Hooks - Modern API with Provider pattern
- ๐ฑ Cross-Platform - iOS and Android support
---
``bash`
npm install @swiftpatch/react-nativeor
yarn add @swiftpatch/react-native
`bash`
cd ios
pod install
cd ..
No additional steps required.
---
`tsx
import { SwiftPatchProvider } from '@swiftpatch/react-native';
export default function App() {
return (
deploymentKey: 'YOUR_DEPLOYMENT_KEY',
serverUrl: 'https://your-server.com/api/v1', // optional
debug: __DEV__,
}}
>
);
}
`
`tsx
import { useSwiftPatch, UpdateStatus } from '@swiftpatch/react-native';
function UpdateButton() {
const {
status,
availableUpdate,
downloadProgress,
checkForUpdate,
downloadUpdate,
installUpdate,
restart,
} = useSwiftPatch();
const handleUpdate = async () => {
// Check for updates
const update = await checkForUpdate();
if (update) {
// Download the update
await downloadUpdate();
// Install and restart
await installUpdate();
restart();
}
};
if (status === UpdateStatus.DOWNLOADING) {
return
}
return (
title={availableUpdate ? 'Update Available' : 'Check for Updates'}
onPress={handleUpdate}
/>
);
}
`
`tsx
import { useSwiftPatchModal, SwiftPatchModal } from '@swiftpatch/react-native';
function App() {
const { showModal } = useSwiftPatchModal();
return (
<>
>
);
}
`
---
`tsx`
interface SwiftPatchConfig {
deploymentKey: string;
serverUrl?: string;
checkOnResume?: boolean;
checkInterval?: number;
installMode?: InstallMode;
mandatoryInstallMode?: InstallMode;
debug?: boolean;
customHeaders?: Record
publicKey?: string;
autoStabilizeAfterLaunches?: number;
}
`tsx
const {
// State
status, // Current update status
downloadProgress, // Download progress (0-100%)
currentBundle, // Currently installed bundle info
availableUpdate, // Available update info
isRestartRequired, // Whether restart is needed
error, // Last error
lastCheckedAt, // Last check timestamp
slotMetadata, // Dual-slot system metadata
environment, // Current environment (PROD/STAGE)
// Actions
checkForUpdate, // Check for available updates
downloadUpdate, // Download available update
installUpdate, // Install downloaded update
restart, // Restart app to apply update
rollback, // Rollback to previous version
clearPendingUpdate, // Clear pending update
getCurrentBundle, // Get current bundle info
stabilize, // Stabilize current bundle
switchEnvironment, // Switch PROD/STAGE environment
getSlotMetadata, // Get slot metadata
markMounted, // Mark app as mounted (crash detection)
downloadStageBundle, // Download staging bundle
} = useSwiftPatch();
`
For use outside React components:
`tsx
import { SwiftPatch } from '@swiftpatch/react-native';
const swiftPatch = new SwiftPatch({
deploymentKey: 'YOUR_KEY',
});
await swiftPatch.init();
const update = await swiftPatch.checkForUpdate();
if (update) {
await swiftPatch.downloadAndInstall(update);
swiftPatch.restart();
}
`
---
`tsx`
enum InstallMode {
IMMEDIATE = 'immediate', // Install and restart immediately
ON_NEXT_RESTART = 'onNextRestart', // Install on next app restart
ON_NEXT_RESUME = 'onNextResume', // Install when app resumes
}
---
SwiftPatch automatically uses differential patching when available:
`tsx
// Server determines if patch is available
// SDK handles full bundle vs patch automatically
await downloadUpdate();
// Patch files are typically 10-50x smaller
// e.g., 50MB bundle โ 2MB patch
`
`tsx
// Crash detection window: 10 seconds
// If app crashes during this window, automatic rollback occurs
const { rollback } = useSwiftPatch();
// Manual rollback
await rollback();
`
`tsx
deploymentKey: 'YOUR_KEY',
publicKey: 'YOUR_RSA_PUBLIC_KEY',
}}
>
// SDK automatically verifies signatures
`
`tsx
const { switchEnvironment, environment } = useSwiftPatch();
// Switch to staging
await switchEnvironment(EnvironmentMode.STAGING);
// Download and test staging bundle
await downloadStageBundle(url, hash);
// Switch back to production
await switchEnvironment(EnvironmentMode.PRODUCTION);
`
---
SwiftPatch v2.0+ fully supports the React Native New Architecture:
iOS (ios/Podfile):`ruby`
ENV['RCT_NEW_ARCH_ENABLED'] = '1'
Android (android/gradle.properties):`properties`
newArchEnabled=true
| Operation | Legacy | TurboModule | Improvement |
|-----------|--------|-------------|-------------|
| Check Update | 15ms | 2ms | 87% faster |
| Get Bundle Info | 8ms | 1ms | 87% faster |
| Native Calls | 3-5ms | 0.5-1ms | 80% faster |
`tsx
import { IS_TURBO_MODULE_ENABLED } from '@swiftpatch/react-native';
console.log('Using TurboModules:', IS_TURBO_MODULE_ENABLED);
`
---
`bash`
npm test
All core functionality is tested:
- Update checking
- Download & installation
- Rollback mechanisms
- Cryptographic verification
- Event handling
---
| Platform | Minimum | Recommended |
|----------|---------|-------------|
| iOS | 13.4+ | 15.0+ |
| Android | API 24+ (7.0) | API 31+ (12) |
| React Native | 0.76.0+ | 0.76.5+ |
| React | 18.2.0+ | 18.3.0+ |
---
- Bundle Signing: Optional RSA signature verification
- HTTPS Only: All downloads over secure connections
- Hash Verification: SHA-256 hash checking for all bundles
- Integrity Checks: Automatic corruption detection
---
| File | Size | Compressed |
|------|------|------------|
| Core JS | ~45KB | ~12KB |
| Native (iOS) | ~150KB | - |
| Native (Android) | ~200KB | - |
---
`bashClone the repository
git clone https://github.com/codewprincee/react-native-swiftpatch.git
---
๐ Troubleshooting
$3
`bash
cd ios
rm -rf Pods Podfile.lock
pod install
cd ..
`$3
`bash
cd android
./gradlew clean
cd ..
`$3
`bash
npm run typescript
``---
MIT License - see LICENSE for details
---
Contributions are welcome! Please read our Contributing Guide first.
---
- ๐ง Email: sdk@swiftpatch.io
- ๐ Issues: GitHub Issues
- ๐ Docs: swiftpatch.io
---
Built with:
- React Native
- bsdiff/bspatch for differential patching
- TypeScript
---
Made with โค๏ธ by the SwiftPatch Team