Reputation: 39
I have an Ionic 2 and Angular 2 application.
And I need to check if the device is rooted (Android case) or jailbroken (Ios case)?
I have tried the following packages (cordova plugins):
cordova plugin add cordova-plugin-iroot --save
IRoot.isRooted(successCallback, failureCallback);
cordova-plugin-root-detection --save
rootdetection.isDeviceRooted(successCallback, errorCallback);
Unfortunately, none of them worked for me... both the plugins have similar implementation
I am not able to import neither IRoot nor rootdetection classes from the npm modules
.
If there is any way to restrict the app installation, please share your response.
Thanks in advance. Piyush
Upvotes: 2
Views: 4169
Reputation: 19036
Related to IRoot Plugin, It can check if the device is rooted (Android case) or jailbroken (Ios case).
Steps:
import cordova-plugin-iroot
package using the command
cordova plugin add cordova-plugin-iroot --save
declare IRoot as a var in the top of your class file
declare var IRoot: any;
make sure to use the core code of the checking when the device is ready
returned data result expected to be boolean NOT number
so you need to check against 'true' NOT '1'
Final script
platform.ready().then(() => {
IRoot.isRooted(
(data) => {
console.log('rooted device detection success case ' + data);
// check data value against true NOT 1
if (data && data === true) {
console.log('This is rooted device');
// ... do anything when device is rooted
} else {
console.log('This is not rooted device');
}
},
(data) => {
console.log('rooted device detection failed case ' + data);
}
);
});
Upvotes: 2
Reputation: 1026
Refer this working code:
RootDetection: Android only
install plugin cordova plugin add cordova-plugin-root-detection
then write these code in app.component.ts
declare var rootdetection:any;
platform.ready().then(() => {
if (typeof(rootdetection) !== 'undefined' && rootdetection) {
rootdetection.isDeviceRooted((data) => {
if (data && data == 1) {
console.log("This is routed device");
} else {
console.log("This is not routed device");
}
}, (data) => {
console.log("routed device detection failed case", data);
});
}
});
iRoot Plugin: Android & iOS
install plugin cordova plugin add cordova-plugin-iroot
then write these code in app.component.ts
declare var IRoot:any;
if (typeof (IRoot) !== 'undefined' && IRoot) {
IRoot.isRooted((data) => {
if (data && data == 1) {
console.log("This is routed device");
} else {
console.log("This is not routed device");
}
}, (data) => {
console.log("routed device detection failed case", data);
});
}
Upvotes: 3