未定义iRoot,第二次启动该应用 [英] iRoot is not defined, 2nd time launch the app
问题描述
首次启动该应用程序时,它可以正常工作,然后从会话中删除该应用程序,然后启动该应用程序,它显示为
When the app is launched the first-time, this is working, after that remove the app from a session, then launch the app, it says
IRoot未定义
IRoot is not defined
declare var IRoot: any;
ngOnInit() {
this._platform.ready().then(() => {
if (typeof (IRoot) !== 'undefined' && IRoot) {
IRoot.isRooted((data) => {
if (data && data == 1) {
this.isRootedORJailBreak = true
console.log("*******This is routed device");
} else {
this.isRootedORJailBreak = false
console.log("*******This is not routed device");
}
}, (data) => {
this.isRootedORJailBreak = false
console.log("*******routed device detection failed case", data);
});
});
} }
推荐答案
似乎在cordova准备就绪时插件尚未准备就绪,或者当时未进行注册.
It seems that the plugin isn't ready when cordova is ready, or isn't doing the registration at time.
您可以尝试使用 setTimeout(()=> {//您的代码},500);将代码包装在
plataform.ready()
内.代码>,看看是否可行.
You can try to wrap up your code inside of the plataform.ready()
with a setTimeout(() => { // your code }, 500);
and see if that works.
我在github上看到了您的问题以及他们给您的答复,但与您在此处尝试过的一样.
I saw your issue in github and the response that they gave you, but is just the same that you have tried here.
更新
将代码移至 ionViewDidEnter
钩子中,这是 this._platform.ready().then(()=> {})
块内的问题 ngOnInit
是它可以被缓存并且只能被调用一次, ionViewDidEnter
总是被调用,无论该组件之前是否已初始化.
Move the code inside of the this._platform.ready().then(() => {})
block to the ionViewDidEnter
hook, the problem with the ngOnInit
is that it can be cached and only will be called one time, the ionViewDidEnter
will be called always, no matters if the component has been initialized before.
问题似乎出在缓存方面.
It seems that the problem was an issue with the cache.
这篇关于未定义iRoot,第二次启动该应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!