angular - 如何限制 Ionic 2 應用程式在已 root 或越獄的裝置上安裝?
我有一個 Ionic 2 和 Angular 2 的應用程式。
我需要檢查設備是否已被 root(Android 情況)或越獄(iOS 情況)?
我已經嘗試了以下套件(Cordova 插件):
cordova plugin add cordova-plugin-iroot --save
IRoot.isRooted(successCallback, failureCallback);cordova-plugin-root-detection --save
rootdetection.isDeviceRooted(successCallback, errorCallback);
不幸的是,它們都對我沒有用……這兩個插件的實現方式相似
我無法從 npm 模組 中導入 IRoot 或 rootdetection 類別。
如果有任何方法可以限制應用程式的安裝,請分享您的回應。
先行感謝。Piyush
答案#1
請參考這段可運行的程式碼:
Root檢測:僅限Android
安裝插件 cordova plugin add cordova-plugin-root-detection
然後將這些程式碼寫入 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 外掛程式:Android 與 iOS
安裝插件 cordova plugin add cordova-plugin-iroot
然後將這些程式碼寫入 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);
});
}
答案#2
關於 IRoot Plugin,它可以檢查設備是否已獲得 root 權限(Android 情況)或已越獄(iOS 情況)。
步驟:
使用以下命令匯入
cordova-plugin-iroot套件
cordova plugin add cordova-plugin-iroot --save在你的類別檔案頂端宣告 IRoot 為一個變數
declare var IRoot: any;當設備準備好時,務必使用檢查的核心代碼
返回的數據結果預期應為布林值,而非數字
所以你需要檢查的是 'true' 而不是 '1'
最終劇本
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);
}
);
});
