React Native client library for ReactPush update system
npm install react-push-clientReact Native client library for ReactPush update system. This library allows React Native apps to check for and download remote bundle updates.
``bash`
npm install react-push-clientor
yarn add react-push-client
Add to ios/Podfile:`ruby`
pod 'RNFS', :path => '../node_modules/react-native-fs'
Then run:
`bash`
cd ios && pod install
Add to android/app/build.gradle:`gradle`
dependencies {
implementation project(':react-native-fs')
}
`javascript
import ReactPush from 'react-push-client';
const reactPush = new ReactPush({
apiKey: 'YOUR_APP_API_KEY',
apiUrl: 'https://your-api-url.com',
appVersion: '1.0.0', // Required: Your app version
userId: 'optional-user-id', // Optional
onUpdateAvailable: (update) => {
console.log('Update available:', update);
},
onUpdateDownloaded: (update) => {
console.log('Update downloaded:', update);
},
onError: (error) => {
console.error('ReactPush error:', error);
},
});
// Check for updates
reactPush.checkForUpdate();
// Or sync automatically
reactPush.sync({
checkFrequency: 'ON_APP_START',
installMode: 'ON_NEXT_RESTART',
});
`
#### checkForUpdate()
Checks for available updates from the server.
#### downloadUpdate(update)
Downloads the update bundle and assets.
#### sync(options)
Automatically checks for updates and downloads them based on the provided options.
Options:
- checkFrequency: 'ON_APP_START' | 'ON_APP_RESUME' | 'MANUAL'installMode
- : 'IMMEDIATE' | 'ON_NEXT_RESTART' | 'ON_NEXT_RESUME'
#### getDownloadedBundleURL()null
Returns the local file path of the downloaded bundle, or if no bundle is downloaded. This can be used by native code to load the bundle.
`javascript`
const bundlePath = await reactPush.getDownloadedBundleURL();
if (bundlePath) {
console.log('Downloaded bundle path:', bundlePath);
}
#### getBundleManager()
Returns the bundle manager instance for advanced usage.
ReactPush provides native classes that can be called directly from iOS and Android code:
objc
#import "ReactPush.h"NSURL *bundleURL = [ReactPush getJsBundleURL:@"main" withExtension:@"jsbundle"];
`$3
`kotlin
import com.reactpush.ReactPushval bundlePath = ReactPush.getJsBundlePath(context, "index.android.bundle")
``See NATIVE_API.md for complete native API documentation.
For manual implementation without the native classes, see NATIVE_IMPLEMENTATION.md.
See INSTALLATION.md for detailed setup instructions.
MIT