Onsen 2-Monaca CLI-Cordova插件怪异行为 [英] Onsen 2 - Monaca CLI - Cordova plugins weird behavior

查看:96
本文介绍了Onsen 2-Monaca CLI-Cordova插件怪异行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始使用Onsen-UI 2及其Monaca CLI工具.这是一个非常棒的工具,非常有帮助.尽管我认为我可以通过查看迁移指南来解决大多数问题,但我还是挑了一个或两个小问题.

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.

我似乎无法弄清的最大问题是插件.我使用Monaca CLI创建我的应用程序(Plain JS Onsen 2.0应用程序),然后继续使用普通的cordova命令添加我的平台和插件.不要问我为什么,我就是这样.在iOS上进行构建时,我获得了构建成功"状态,并且我的应用在模拟器和设备上运行良好.问题是当我尝试使用插件提供的功能时.

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.

我尝试实现Card.io插件(已成功安装),并且我的应用程序正常启动.我有一个准备在设备上启动以检查插件是否正常工作的函数,即"canScan"函数,该函数显示结果警报.但是,即使设备已准备就绪,也不会发生任何事情.怪异的行为是这样的:当我将应用程序置于后台,或打开多任务处理窗口(双击主页按钮)然后返回到该应用程序时,该警报就会显示并显示我可以扫描的消息.收到此消息后,我应该可以点击一个按钮,并且Card.io界面应该会出现,但是同样,当我点击按钮时,什么也没有发生.仅当我执行与以前相同的操作(输入多任务并返回到应用程序)时,Card.io界面才会出现,但会冻结该应用程序.

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?

这是我的"onDeviceReady"功能:

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>

我还尝试通过Monaca工具安装插件:

I also tried installing the plugin via the Monaca tools:

$ monaca plugin add <plugin-name>

任何帮助或建议将不胜感激!

Any help or advice will be greatly appreciated!

推荐答案

将onDeviceReady函数移到单独的.js文件中,看看是否可以解决问题.

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

这篇关于Onsen 2-Monaca CLI-Cordova插件怪异行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆