Package Exports
- react-native-codepush-sdk
- react-native-codepush-sdk/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-native-codepush-sdk) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
React Native CodePush SDK
A comprehensive SDK for integrating CodePush-style over-the-air updates into your React Native apps, with support for custom servers and advanced update workflows.
Looking for a working demo app? See the
example/folder for a full React Native project that consumes this SDK.
Features
🚀 Core Functionality
- Custom Server Integration: Connect to your own CodePush server
- Over-the-Air Updates: Download and install app updates without app store releases
- Rollback Support: Automatically rollback failed updates
- Progress Tracking: Real-time download and installation progress
- Mandatory Updates: Support for required updates that users cannot skip
📱 Platform Support
- iOS: Full native integration
- Android: Complete Android support
- Cross-Platform: Unified API for both platforms
🔧 Advanced Features
- Gradual Rollouts: Support for percentage-based rollouts
- Update Validation: Verify update integrity before installation
- Offline Support: Handle updates when network is unavailable
- Background Downloads: Download updates in the background
- Custom Install Modes: Immediate, on restart, or on resume installation
Installation
1. Install Dependencies
npm install react-native-fs react-native-zip-archive react-native-device-info @react-native-async-storage/async-storage2. Platform Setup
iOS Setup
- Run
cd ios && pod install - Add the following to your
Info.plist:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>Android Setup
- Add permissions to
android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />Usage
Basic Setup
import React from 'react';
import { SafeAreaView } from 'react-native';
import { CodePushProvider } from './src/sdk/CodePushProvider';
import UpdateChecker from './src/components/UpdateChecker';
const App: React.FC = () => {
const codePushConfig = {
serverUrl: 'https://your-custom-codepush-server.com',
deploymentKey: 'your-deployment-key-here',
appVersion: '1.0.0',
checkFrequency: 'ON_APP_START',
installMode: 'ON_NEXT_RESTART',
};
return (
<CodePushProvider config={codePushConfig} autoCheck={true}>
<SafeAreaView style={{ flex: 1 }}>
<UpdateChecker />
</SafeAreaView>
</CodePushProvider>
);
};
export default App;Using the Hook
import { useCodePush } from './src/sdk/CodePushProvider';
const MyComponent = () => {
const {
availableUpdate,
isChecking,
checkForUpdate,
syncUpdate,
} = useCodePush();
return (
<View>
{availableUpdate && (
<Button title="Install Update" onPress={syncUpdate} />
)}
<Button
title="Check for Updates"
onPress={checkForUpdate}
disabled={isChecking}
/>
</View>
);
};Manual Integration
import CustomCodePush from './src/sdk/CustomCodePush';
const codePush = new CustomCodePush({
serverUrl: 'https://your-server.com',
deploymentKey: 'your-key',
appVersion: '1.0.0',
});
// Check for updates
const update = await codePush.checkForUpdate();
// Download and install
if (update) {
const localPackage = await codePush.downloadUpdate(update, (progress) => {
console.log(`Download progress: ${progress.receivedBytes}/${progress.totalBytes}`);
});
await codePush.installUpdate(localPackage);
}Server Implementation
Your custom CodePush server needs to implement these endpoints:
Check for Updates
POST /api/v1/updates/checkReport Installation
POST /api/v1/updates/reportReport Rollback
POST /api/v1/updates/rollbackSee src/api/server-example.md for detailed API documentation.
Configuration Options
interface CodePushConfiguration {
serverUrl: string; // Your server URL
deploymentKey: string; // Deployment key for authentication
appVersion: string; // Current app version
checkFrequency?: 'ON_APP_START' | // When to check for updates
'ON_APP_RESUME' |
'MANUAL';
installMode?: 'IMMEDIATE' | // When to install updates
'ON_NEXT_RESTART' |
'ON_NEXT_RESUME';
minimumBackgroundDuration?: number; // Minimum background time before checking
}API Reference
CustomCodePush Class
Methods
checkForUpdate(): Check if an update is availabledownloadUpdate(update, progressCallback): Download an update packageinstallUpdate(localPackage): Install a downloaded updatesync(options, statusCallback, progressCallback): Complete sync processgetCurrentPackage(): Get current installed package inforollback(): Rollback to previous versionclearUpdates(): Clear all downloaded updates
CodePushProvider Component
Props
config: CodePush configuration objectautoCheck: Automatically check for updates on app startcheckOnResume: Check for updates when app resumes
useCodePush Hook
Returns
codePush: CustomCodePush instancecurrentUpdate: Currently installed update infoavailableUpdate: Available update infosyncStatus: Current sync statusisChecking: Whether checking for updatesisDownloading: Whether downloading an updateisInstalling: Whether installing an updatecheckForUpdate(): Function to check for updatessyncUpdate(): Function to sync and install updatesrollback(): Function to rollback updatesclearUpdates(): Function to clear all updates
Update Package Format
Update packages should be ZIP files with this structure:
package.zip
├── index.bundle # Main JavaScript bundle
├── index.bundle.map # Source map (optional)
├── assets/ # Static assets
│ ├── images/
│ ├── fonts/
│ └── ...
└── metadata.json # Package metadataSecurity Considerations
- HTTPS Only: Always use HTTPS for your server
- Authentication: Validate deployment keys on server
- Package Signing: Consider signing update packages
- Rate Limiting: Implement rate limiting on your server
- Rollback Protection: Implement automatic rollback for failed updates
Troubleshooting
Common Issues
- Network Errors: Check server URL and network connectivity
- Permission Errors: Ensure file system permissions are granted
- Bundle Errors: Verify update package format and integrity
- Installation Failures: Check available storage space
Debug Mode
Enable debug logging by setting:
// Add to your configuration
const config = {
// ... other config
debug: true,
};Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
MIT License - see LICENSE file for details.
Support
For issues and questions:
- Check the troubleshooting section
- Review the server API documentation
- Create an issue in the repository