Onsen 2 - Monaca CLI - Cordova plugins weird behavior

允我心安 提交于 2020-01-06 15:50:16

问题


I recently started using Onsen-UI 2 and with it Monaca CLI tools. It's a pretty awesome tool, very helpful. There is one or two niggles I've picked up though, although I think I can solve most of them by looking at migration guides.

The biggest issue that I can't seem to figure out is the plugins. I create my app (Plain JS Onsen 2.0 app) with the Monaca CLI, and then proceed to use normal cordova commands to add my platforms and plugins. Don't ask me why, I just like it that way. When building for iOS I get build "Success" status and my app runs fine in emulator and on my device. The issue is when I try to use features provided by plugins.

I tried implementing the Card.io plugin (installed successfully) and my app launches just fine. I have a function that fires on device ready to check whether or not the plugin is working, a "canScan" function, that shows an alert with the result. However, even though the device is ready, nothing happens. The weird behavior is this: when I put the app in the background, or open multitasking window (double tap home button) and then come back to the app, then the alert shows up with the message that I can scan. After receiving this message, I should be able to tap a button and the Card.io interface should appear, but again, nothing happens when I tap the button. Only if I do the same as before (enter multitasking and come back to the app) then the Card.io interface appears, but freezes the app.

I thought there was an issue with my implementation of the plugin, i.e. my code is wrong, but this happens with other plugins too.

Any ideas as to what is going on here?

This is my "onDeviceReady" function:

document.addEventListener('deviceready', function() {
    CardIO.canScan(onCardIOCheck);
}, false);

This is how I installed the plugin:

$ cordova plugin add <plugin-name>

I also tried installing the plugin via the Monaca tools:

$ monaca plugin add <plugin-name>

Any help or advice will be greatly appreciated!


回答1:


Move your onDeviceReady function out to a separate .js file and see if that solves the issue.



来源:https://stackoverflow.com/questions/39759299/onsen-2-monaca-cli-cordova-plugins-weird-behavior

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!