react-native-app-update
Getting started
$ npm install github:odemolliens/react-native-app-update#1.0.0 --save
Manual installation
iOS
-
In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
-
Go to
node_modules
➜react-native-app-update
and addODAppUpdate.xcodeproj
-
In XCode, in the project navigator, select your project. Add
libODAppUpdate.a
to your project'sBuild Phases
➜Link Binary With Libraries
-
Run your project (
Cmd+R
)<
Android
- Open up
android/app/src/main/java/[...]/MainActivity.java
-
Add
import com.odemolliens.appupdate.ODAppUpdatePackage;
to the imports at the top of the file -
Add
new ODAppUpdatePackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:
include ':react-native-app-update'
project(':react-native-app-update').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-app-update/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:
implementation project(':react-native-app-update')
Setup iOS
- Open up
AppDelegate.m
-
Add a new import
#import <ODAppUpdate/AppUpdateListenerSingleton.h>
-
Add a private interface :
@interface AppDelegate () <AppVersionListener>
@end
- Add
[AppUpdateListenerSingleton sharedManager:self];
in the methodapplication:didFinishLaunchingWithOptions
- Add the new protocol:
- (void)checkMigrationAppVersion:(NSMutableDictionary*)storedVersion
andCurrentVersion:(NSMutableDictionary*)currentVersion {
int majorStoredVersion = [[storedVersion objectForKey:@"major"]intValue];
int minorStoredVersion = [[storedVersion objectForKey:@"minor"]intValue];
int versionStoredCode = [[storedVersion objectForKey:@"version"]intValue];
int majorCurrentVersion = [[currentVersion objectForKey:@"major"]intValue];
int minorCurrentVersion = [[currentVersion objectForKey:@"minor"]intValue];
int versionCurrentCode = [[currentVersion objectForKey:@"version"]intValue];
// Check and handle app version update
}
Setup Android
- Open up
MainApplication.java
:
- Add in the
getPackages
method:
new ODAppUpdatePackage(new AppVersionListener() {
@Override
public void checkMigrationAppVersion(Map<String, Integer> storedVersion,
Map<String, Integer> currentversion) {
int majorStoredVersion = storedVersion.get("major");
int minorStoredVersion = storedVersion.get("minor");
int versionStoredCode = storedVersion.get("version");
int majorCurrentVersion = currentversion.get("major");
int minorCurrentVersion = currentversion.get("minor");
int versionCurrentCode = currentversion.get("version");
// Check and handle app version update
}
})
Usage
The version of your project must respect the following format : Major.Minor.Version
. For example, it can be : 1.0.0
.
import ODAppUpdate from 'react-native-app-update';
// Put this where you want to check and handle the app update
// (maybe in the constructor of your App component ?)
ODAppUpdate.appVersion()
.then(response => {
let majorStoredVersion = response.currentStoredVersion.major;
let minorStoredVersion = response.currentStoredVersion.minor;
let versionStoredCode = response.currentStoredVersion.version;
let majorCurrentVersion = response.currentVersion.major;
let minorCurrentVersion = response.currentVersion.minor;
let versionCurrentCode = response.currentVersion.version;
// Handle new update
})
.catch(error => {
// An error occured
});