Piyush Gorey
Piyush Gorey

Reputation: 39

How to restrict Ionic 2 application installation if device is rooted or jail broken?

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):

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

Answers (2)

Ahmed Nabil
Ahmed Nabil

Reputation: 19036

Related to IRoot Plugin, It can check if the device is rooted (Android case) or jailbroken (Ios case).

Steps:

  1. import cordova-plugin-iroot package using the command
    cordova plugin add cordova-plugin-iroot --save

  2. declare IRoot as a var in the top of your class file
    declare var IRoot: any;

  3. make sure to use the core code of the checking when the device is ready

  4. 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

Raja Mohamed
Raja Mohamed

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

Related Questions