2

I've tried many different combinations of files and code to get these phonegap build plugins to function, but so far nothing has worked.

This is the beginning of the index.html I think should work (all but the first script include are not phonegap plugins or directly related to 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>

This is the 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>

Testing to see whether the objects OAuth (for oauth.io) or window.plugins.pushNotification (for PushPlugin) are defined or not, I am always getting that they are undefined.

In the folder I have everything together, like:

  1. (Essential Files)
    • config.xml
    • icon.png
    • index.html
  2. (App-specific files)
    • printR.js
    • pushNotif.js
    • tAuth.js

(Everything is in one folder, I just separated them in the list.)

So it's pretty simple and straightforward, just as I thought the instructions entailed. However, it's not working, unfortunately.

I tried having the phonegap.js file included, including cordova.js instead, having the file cordova.js, and including the js for the plugins, but I don't think it works that way, so the way I presented is what I think is supposed to be how it's supposed to be set up.


This is the script I'm using to handle and check for the phonegap plugin 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);
    }
}

If I include the PushNotification.js script, I see that window.plugins.pushNotification is not undefined. However, with phonegap build, I think it may be designed to include it automatically. If I don't include it manually (copying the file PushNotification.js from the git repository to the project files and including it specifically), I get that that object is not defined. However, in the phonegap build dashboard, it shows me that the plugin is indeed included.

JVE999
  • 3,327
  • 10
  • 54
  • 89

1 Answers1

1

Your config.xml is invalid. These lines are bad:

<!doctype html>
<html>
<head>
Raymond Camden
  • 10,661
  • 3
  • 34
  • 68
  • I apologize, that was an error in my question. The question looked like I had forgotten to put those lines at the top of the `index.html` code, so I copied and haphazardly pasted them in the `config.xml` code. In reality, I had just not left enough space preceding, so those lines didn't show up. The question is fixed now. – JVE999 Oct 13 '14 at 19:02
  • In your project, when you click the Plugins tab, is anything listed? – Raymond Camden Oct 14 '14 at 10:25
  • All of the plugins are listed properly. And I found out some of them are being included. There's just one in particular, `com.oauthio.plugins.oauthio` that doesn't function properly. Not sure what to do with the question as it's technically now probably a different question -- one concerning a specific plugin. – JVE999 Oct 14 '14 at 17:42
  • Actually, the original question still applies. The push notifications plugin `PushPlugin` is not acting in any way as I would expect. The script I'm using is based off of the documentation script. I have added it to the question. I checked for the `device` object, and that is `undefined`. I have to include `PushNotification.js` for the object `window.plugins.pushnotification` to not be undefined, although I thought that perhaps phonegap build injected the script into the page as a part of the plugin procedure. – JVE999 Oct 14 '14 at 22:41
  • @Ajoy I never did. I'm using cordova locally now. – JVE999 Dec 04 '14 at 09:32