user1840352
user1840352

Reputation: 183

Onsen 2 - Monaca CLI - Cordova plugins weird behavior

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!

Upvotes: 0

Views: 388

Answers (1)

sj.meyer
sj.meyer

Reputation: 885

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

Upvotes: 1

Related Questions