PhoneGap的生成API调用不点火 [英] Phonegap Build API calls not firing

查看:189
本文介绍了PhoneGap的生成API调用不点火的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery Mobile和PhoneGap的构建应用程序。在jQuery Mobile的JavaScript的code正常工作,但是JavaScript的code不似乎工作的PhoneGap。该应用程序它使用多HTML模板,和我做了登录应用程序的索引文件。

I'm making an application using jQuery Mobile and Phonegap Build. The jQuery Mobile javascript code works fine, however the phonegap javascript code doesn't seems to be working. The application it's using a multiple html template, and I made the login the index file of the application.

我使用PhoneGap的版本3.1.0(当前默认为构建服务)

I'm using phonegap version 3.1.0 (current default for build service)

我添加以下线路中的config.xml文件:

I'm adding the following lines in the config.xml file:

<gap:plugin name="org.apache.cordova.device" />
<gap:plugin name="org.apache.cordova.file" />

然后,在index.html的,我在头部添加以下脚本:

Then, at index.html, I'm adding the following scripts at the header:

<script src="phonegap.js"></script>
<script src="js/settings_page.js"></script>
<script src="js/jquery-2.0.3.min.js"></script>
<script src="js/jquery-mobile-events.js"></script>
<script src="js/jquery.mobile-1.4.1.min.js"></script>

该文件SETTINGS_PAGE包括一些基本的PhoneGap API互动,这万一在写入本地存储一些默认值它们不是设置:

The settings_page file includes some basic phonegap API interaction, which writes some default values in local storage in case they're not set:

console.log('added');

document.addEventListener('deviceready', deviceReady, false);

function deviceReady() {

   console.log('called');

   var application_settings = window.localStorage;

   //if no settings have been created, create them
   if (application_settings('defaults') === null) {
       application_settings.setItem('defaults', 'true');
       application_settings.setItem('type', 'all');
       application_settings.setItem('sport', 'all');
       application_settings.setItem('customer', 'all');
       application_settings.setItem('order', 'date');
       application_settings.setItem('refresh', 'never');
       console.log('defaults set');
   }

}

使用纹波模拟器我可以看到在控制台日志中的添加评论,但从未达到的'叫'之一,如果我运行应用程序并使用weinre调试它,没有控制台登录寄存器。

Using ripple emulator I can see the 'added' comment in the console log, however never reaches the 'called' one, and if I run the application and use weinre to debug it, none of the console logs registers.

在案件没有按键都正在发生,但我没有得到任何错误,要么,我失去的东西吗?我改变了功能插件,在这里建议的PhoneGap构建3.1设备不定义这里 HTTP: //www.raymondcamden.com/index.cfm/2013/10/1/PhoneGap-Build-and-PhoneGap-30 但它仍然没有工作,任何帮助是非常AP preciated

In both cases none of the keys are being generated, but I'm not getting any errors either, am I missing something? I changed the features to plugins as suggested in here PhoneGap 3.1 Build Device Is Not Defined and here http://www.raymondcamden.com/index.cfm/2013/10/1/PhoneGap-Build-and-PhoneGap-30 but it's still not working, any help is highly appreciated

推荐答案

确定后调试和测试的时间我解决了这个问题,我认为这可能是对未来有益的参考任何其他的PhoneGap构建用户,这样我会名单一步一步的指导对我做了什么在这里了。我不知道这是最好的办法了,所以我真的AP preciate的东西一些反馈,可以加以改进:)

Ok after hours of debugging and testing I solved the issue, I think this can be helpful for future references to any other phonegap build users so I'm gonna list step by step guide on what I did in here. I don't know if this is the best approach though, so I'd really appreciate some feedback on things that can be improved :)

若要使用jQuery的工作的PhoneGap构建和PhoneGap的API,你需要做在你的应用程序的索引如下:

To make jQuery work with Phonegap Build and Phonegap API you need to do the following in your application's index:


  • 请注意,API调用不会在模拟器中运行,你需要一个真实的设备来检查了这一点。 (感谢@Dato'穆罕默德Nurdin这个有价值的信息)

  • 添加到PhoneGap的脚本参考&LT; SCRIPT SRC =phonegap.js&GT;&LT; / SCRIPT&GT; 理想情况下这可能是您的第一个脚本参考,不要求任何库工作,你不需要有库本身,一旦它编译code的PhoneGap构建将增加它。

  • 添加jQuery的引用(如果你需要它,因为我与jQuery Mobile的工作,我会需要它)

  • 设备准备将在您的索引文件时,您接下来添加事件侦听器,在其他脚本中添加这将导致与设备ready事件的一些问题。但是,如果你需要检查其他脚本设备就绪状态,您可以添加一个全局变量可用于所有脚本的波纹管,如果你不知道你可以创建一个脚本变量,这将使其可用于所有的脚本这一项后参考。例如:&LT;脚本&GT; VAR phonegap_ready = FALSE&LT; / SCRIPT&GT;

  • 添加脚本与事件侦听器

  • Please note the API calls won't run in the emulator, you need a real device to check this out. (Thanks @Dato' Mohammad Nurdin for this valuable information)
  • Add a reference to the phonegap script <script src="phonegap.js"></script> ideally this can be your first script reference, it doesn't requires any library to work and you don't need to have the library itself, phonegap build will add it once it compiles the code.
  • Add jQuery reference (in case you need it, since I was working with jQuery Mobile I'll need it)
  • Device ready will take place in your index file when you'll next add the event listener, adding this in other scripts will cause some issues with the device ready event. But if you need to check the device ready status in other scripts, you can add a global variable available for all of the scripts bellow, if you don't know how you can create a script with a variable, this will make it available for all the scripts referenced after this one. Example: <script>var phonegap_ready = false</script>
  • add a script with your event listener

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    phonegap_ready = true;
}


  • 添加jQuery Mobile的和你的js事件和code文件的来源。

  • 作为一个方面说明,检查设备准备与jQuery Mobile的工作,而这只是一个标准,一些测试后,我跑了,PhoneGap的设备就绪火灾方式比jQuery的pageshow事件(这是有道理考虑所有的DOM操作JQM的来得更快页面事件做),但是我还是推荐它只是作为一种警示。

    As a side note, checking for device ready while working with jQuery Mobile it's just a standard, after some test I ran, phonegap device ready fires way more faster than jQuery pageshow event (which makes sense considering all of the DOM manipulation jqm page events do) however I still recommend it just as a caution.

    一旦在code您可以使用递延呼叫 $。当()异步检查不执行PhoneGap的电话,直到PhoneGap的框架是完全可操作。作为使用previously全局变量,创建了一个例子:

    Once in your code you can use the deffered call $.when() to check asynchronously to not execute the phonegap calls until the phonegap framework is fully operational. As an example using the previously global variable created:

    $(document).on('pageshow', '#login_page', function (parent_event) {
        //do jQuery Mobile event handlings here
        $.when(phonegap_ready === true).then(function () {            
            phonegapApiFunctionsCall();
        });
    });
    

    如果功能或插件(到PhoneGap的API调用之前的PhoneGap作为特征进行建设3.0,并作为的PhoneGap构建的这些3.0​​被替换为插件),你就可以从phonegapApiFunctionsCall运行API命令()和将避免PhoneGap的deviceready事件和jQuery Mobile的页面初始化事件之间的初始化的问题。

    If the features or plugins (calls to phonegap API are performed as features before Phonegap Build 3.0, and as of Phonegap Build 3.0 these were replaced for plugins) you'll be able to run the API commands from the phonegapApiFunctionsCall() and will avoid the initialization issues between phonegap deviceready event and jQuery Mobile page initialization events.

    这篇关于PhoneGap的生成API调用不点火的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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