Many times we need to check the integrity of phones that your app is installed in order to protect data integrity.
- Identify whether an iPhone is jail broken.
- Identify whether an Android device is rooted.
- Add security levels: HIGH, MEDIUM, LOW for consumer and enterprise apps.
For Consumer based apps the MEDIUM or LOW security level is appropriate but for consumer facing apps HIGH security level.
$ yarn add react-native-root-detection
$ react-native link react-native-root-detection
after running react-native link do following changes.
MainApplication.java
- import com.reactspace.rootDetection.RNRootDetectionPackage;
+ import com.reactspace.rootDetection.react.RNRootDetectionPackage;
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-root-detection
and addRNRootDetection.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNRootDetection.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Run your project (
Cmd+R
)<
- Open up
android/app/src/main/java/[...]/MainApplication.java
- Add
import com.reactspace.rootDetection.react.RNRootDetectionPackage;
to the imports at the top of the file - Add
new RNRootDetectionPackage()
to the list returned by thegetPackages()
method
- Add
- Append the following lines to
android/settings.gradle
:include ':react-native-root-detection' project(':react-native-root-detection').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-root-detection/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:implementation project(':react-native-root-detection')
How to use from android:
You'll need to get a API key from the Google developer console to allow you to verify with the
Android Device Verification API
public class MainActivity extends ReactActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// code...
RootDetectorConfig config = new RootDetectorConfig();
config.setGoogleApiKey("<-- Google Api Key -->");
config.setLevel(SecurityLevel.HIGH);
RootDetector.checkDeviceRootStatus(this, config, new Callback() {
@Override
public void onResult(boolean isRooted) {
// code...
}
@Override
public void onError(Exception e) {
// code...
}
});
}
}
How to use from javascript:
import { checkRootStatus, SecurityLevel } from 'react-native-root-detection';
const config = {
googleApiKey: '<-- Google Api Key -->',
securityLevel: SecurityLevel.HIGH
};
checkRootStatus(config).then((isRooted) => {
// ...
}).catch(() => {
// ...
})
In order to call the methods within the SafetyNet Attestation API, you must pass in an API key. To create this key, complete the following steps:
- Go to the Library page in the Google APIs Console.
- Search for the Android Device Verification API. When you've found the API, click on it. The Android Device Verification API dashboard screen appears.
- If the API isn't already enabled, click Enable.
- If the Create credentials button appears, click on it to generate an API key. Otherwise, click the All API credentials drop-down list and select the API key that is associated with the project for which the Android Device Verification API is enabled.
- In the sidebar on the left, click Credentials. Copy the API key that appears.
Contact
In case of any help feel free to mail at [email protected]