【问题标题】:Phonegap build plugins are not being included不包括 Phonegap 构建插件
【发布时间】:2014-10-13 05:52:25
【问题描述】:

我尝试了许多不同的文件和代码组合来让这些 phonegap 构建插件正常工作,但到目前为止没有任何效果。

这是我认为应该可以工作的 index.html 的开头(除了第一个脚本之外的所有内容都不是 phonegap 插件或与 phonegap 直接相关):

<!doctype html>
<html>
<head>
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>

<script type="text/javascript" charset="utf-8" src="jquery-2.1.1.min.js"></script>
<script type="text/javascript" charset="utf-8" src="pushNotif.js"></script>
<script type="text/javascript" charset="utf-8" src="tAuth.js"></script>
<script type="text/javascript" charset="utf-8" src="printR.js"></script>
<script type="text/javascript" charset="utf-8" src="clearCache.js"></script>

这是config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns="http://www.w3.org/ns/widgets"
    xmlns:gap = "http://phonegap.com/ns/1.0" id="com.example.example" version="0.0.1">
    <name>Example</name>
    <icon src="icon.png" />
    <description>
        Example app.
    </description>
    <author email="support@example.com" href="https://example.com">
        Example
    </author>
    <content src="index.html" />
    <access origin="*" />
    <preference name="phonegap-version" value="3.5.0" />
    <feature name="Geolocation">
        <param name="ios-package" value="CDVLocation" />
    </feature>
    <gap:plugin name="org.apache.cordova.inappbrowser" version="0.5.2" />
    <gap:plugin name="com.oauthio.plugins.oauthio" version="0.2.4" />
    <gap:plugin name="com.phonegap.plugins.pushplugin" version="2.4.0" />
    <gap:plugin name="org.apache.cordova.dialogs" version="0.2.10" />
    <gap:plugin name="org.apache.cordova.geolocation" version="0.3.10" />
</widget>

测试对象OAuth(对于oauth.io)或window.plugins.pushNotification(对于PushPlugin)是否已定义,我总是发现它们是未定义的。

在文件夹中,我将所有内容放在一起,例如:

  1. (基本文件)
    • config.xml
    • icon.png
    • index.html
  2. (应用程序特定文件)
    • printR.js
    • pushNotif.js
    • tAuth.js

(所有内容都在一个文件夹中,我只是在列表中将它们分开。)

所以它非常简单明了,正如我认为的说明所需要的那样。但是,不幸的是,它不起作用。

我尝试包含 phonegap.js 文件,包括 cordova.js,包含文件 cordova.js,并包含插件的 js,但我认为它不是那样工作的,所以我介绍的方式是我认为应该是应该如何设置的。


这是我用来处理和检查 phonegap 插件 pushplugin 的脚本:

if(typeof window.plugins != "undefined" &&
    typeof window.plugins.pushNotification != "undefined"){
    alert("phonegap pushplugin plugin IS included");//this worked
    handlePushNotif();
} else {
    alert("phonegap pushplugin plugin not included");
}

function handlePushNotif(){
    //https://github.com/phonegap-build/PushPlugin/tree/93067b9303252d5ed7394819bf220db56d99d22c

    var pushNotification;
    pushNotification = window.plugins.pushNotification;

    //register
    //Get your senderID by signing into to your google dashboard. The //senderID is found at Overview->Dashboard->Project Number.
    if ( device.platform == 'android' || device.platform == 'Android' )
    {
        pushNotification.register(
            successHandler,
            errorHandler, {
                "senderID":"888264849750",
                "ecb":"onNotificationGCM"
            });
    }
    else
    {
        pushNotification.register(
            tokenHandler,
            errorHandler, {
                "badge":"true",
                "sound":"true",
                "alert":"true",
                "ecb":"onNotificationAPN"
            });
    }
    // result contains any message sent from the plugin call
    function successHandler (result) {
        alert('result = ' + result);
    }

    // result contains any error description text returned from the plugin call
    function errorHandler (error) {
        alert('error = ' + error);
    }

    //tokenHandler (iOS ony) - called when the device has registeredwith a unique device token.
    function tokenHandler (result) {
        // Your iOS push server needs to know the token before it can push to this device
        // here is where you might want to send it the token for later use.
        alert('device token = ' + result);
    }
}

如果我包含 PushNotification.js 脚本,我会看到 window.plugins.pushNotification 不是 undefined。但是,对于 phonegap 构建,我认为它可能被设计为自动包含它。如果我不手动包含它(将文件 PushNotification.js 从 git 存储库复制到项目文件并专门包含它),我会发现该对象未定义。但是,在 phonegap 构建仪表板中,它显示该插件确实包含在内。

【问题讨论】:

    标签: javascript cordova phonegap-pushplugin


    【解决方案1】:

    您的 config.xml 无效。这些行很糟糕:

    <!doctype html>
    <html>
    <head>
    

    【讨论】:

    • 我很抱歉,这是我的问题中的一个错误。这个问题看起来好像我忘记将这些行放在index.html 代码的顶部,所以我复制并随意将它们粘贴到config.xml 代码中。实际上,我只是没有在前面留下足够的空间,所以那些行没有出现。现在问题已经解决了。
    • 在您的项目中,当您单击“插件”选项卡时,是否列出了任何内容?
    • 所有插件都正确列出。我发现其中一些被包括在内。只有一个特别是 com.oauthio.plugins.oauthio 无法正常运行。不确定如何处理这个问题,因为从技术上讲,它现在可能是一个不同的问题——一个关于特定插件的问题。
    • 其实原来的问题还是适用的。推送通知插件PushPlugin 并没有像我预期的那样发挥作用。我使用的脚本基于文档脚本。我已将其添加到问题中。我检查了device 对象,即undefined。我必须包含PushNotification.js 才能使对象window.plugins.pushnotification 未被定义,尽管我认为可能是phonegap build 将脚本作为插件过程的一部分注入到页面中。
    • @Ajoy 我从来没有这样做过。我现在在本地使用cordova。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-14
    • 2023-03-15
    • 2014-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多