“les plugins n'est pas défini” dans l'Application PhoneGap

Je suis en train d'essayer d'utiliser le PhoneGap LocalNotification Plugin,
en utilisant Android 4.1 avec Cordova 2.0.0 et Sketcha (Bibliothèque d'INTERFACE utilisateur).

Mise à JOUR #2 20/9/12: j'ai utilisé Bozzzi code avec quelques corrections:

  1. Ajouté }) à la fin de localnotification.js (erreur de syntaxe).
  2. changé cordova.define("cordova/plugin/LocalNotification", function(require, exports, module):
    cordova.define("cordova/plugin/LocalNotification", function(require, exports, module),
    si les modules de nom de match pour cette fonction (avant le module n'a pas été trouvé):

    fenêtre.les plugins.LocalNotification =
    cordoue.require("cordova/plugin/LocalNotification");

  3. changement de ceci:

    if (!de la fenêtre.plugins) {
    de la fenêtre.plugins = {};
    }
    else if (!de la fenêtre.les plugins.LocalNotification) {
    de la fenêtre.les plugins.LocalNotification = cordova.require("cordova/plugin/LocalNotification");
    }

:

if (!window.plugins) {
    window.plugins = {};
}

if (!window.plugins.LocalNotification) {
    window.plugins.LocalNotification = cordova.require("cordova/plugin/LocalNotification");
}

avant ce changement, si la fenêtre.les plugins n'est pas trouvé, il sera créé, mais la fenêtre.les plugins.LocalNotification ne serait pas.

Après toutes ces corrections, j'obtiens cette erreur:

> 09-20 01:22:27.355: D/CordovaLog(8297):
> file:///android_asset/www/index.html: Line 21 : PAPA AMERICANO ready
> 09-20 01:22:27.360: I/Web Console(8297): PAPA AMERICANO ready at
> file:///android_asset/www/index.html:21 09-20 01:22:27.370:
> D/CordovaLog(8297): Uncaught TypeError: Cannot call method 'add' of
> undefined 09-20 01:22:27.375: D/CordovaLog(8297):
> file:///android_asset/www/index.html: Line 35 : Uncaught TypeError:
> Cannot call method 'add' of undefined 09-20 01:22:27.375: E/Web
> Console(8297): Uncaught TypeError: Cannot call method 'add' of
> undefined at file:///android_asset/www/index.html:35 09-20
> 01:22:29.185: D/DroidGap(8297): onMessage(spinner,stop) 09-20
> 01:22:30.255: E/SKIA(8297): FimgApiStretch:stretch failed 09-20
> 01:22:41.755: E/SKIA(8297): FimgApiStretch:stretch failed 09-20
> 01:22:52.565: D/CordovaWebView(8297): >>> loadUrlNow() 09-20
> 01:22:52.565: D/webkit(8297): Firewall not null 09-20 01:22:52.565:
> D/webkit(8297): euler: isUrlBlocked = false

Pour une raison quelconque, le cordova.require("cordova/plugin/LocalNotification") ne mettez pas le window.plugins.LocalNotification valeur et il continue à être défini.
Voici ma mise à jour index.html (mise à Jour #2):

<!DOCTYPE HTML>
<html manifest="" lang="en-US">
<head>
    <meta charset="UTF-8">
    <title>AndroidSencha</title>
    <script id="microloader" type="text/javascript" src="cordova-2.0.0.js"></script>
    <script id="microloader" type="text/javascript" src="LocalNotification.js"></script>
    <script id="microloader" type="text/javascript">

    function onDeviceReady() {
        if (!window.plugins) {
            window.plugins = {};
        } else if (!window.plugins.LocalNotification) {
            window.plugins.LocalNotification = cordova.require("cordova/plugin/LocalNotification");
        }
    }

    window.document.addEventListener("deviceready", appReady, false);

    function appReady() {
        console.log("PAPA AMERICANO ready");

        var d = new Date();
        d = d.getTime() + 2 * 1000; //60 seconds from now
        d = new Date(d);

        if (!window.plugins) {
            window.plugins = {};
        }

        if (!window.plugins.LocalNotification) {
            window.plugins.LocalNotification = cordova.require("cordova/plugin/LocalNotification");
        }

        window.plugins.localNotification.add({
            date: d,
            message: 'This is an Android alarm using the statusbar',
            id: 123
        });
    }

    </script>
    <style type="text/css">
         /**
         * Example of an initial loading indicator.
         * It is recommended to keep this as minimal as possible to provide instant feedback
         * while other resources are still being loaded for the first time
         */
        html, body {
            height: 100%;
            background-color: #1985D0
        }

    </style>

    <!-- The line below must be kept intact for Sencha Command to build your application -->
    <script id="microloader" type="text/javascript" src="sdk/microloader/development.js"></script>
        <style type="text/css">
.loadingText{
color: white;
font-family: "Avant Garde", Avantgarde, "Century Gothic", CenturyGothic, "AppleGothic", sans-serif;
text-align: center;
font-size: 20px;
padding-top: 10%;
}
</style>
</head>
<body>
    <div id="appLoadingIndicator">
    <div class="loadingText"><div style="margin-bottom: 10px;">Loading, Please wait..</div>
    <div><img src="resources\images\smileloading.gif"></div></div>
    </div>

</body>
</html>

Voici mon localnotificaiton.js après mon fixe (mise à Jour #2):

cordova.define("cordova/plugin/LocalNotification", function(require, exports, module) {      

var exec = require("cordova/exec");
var LocalNotification = function () {};

LocalNotification.prototype.add = function(options) {
            var defaults = {
                date : new Date(),
                message : '',
                ticker : '',
                repeatDaily : false,
                id : ""
            };
        if (options.date) {
                options.date = (options.date.getMonth()) + "/" + (options.date.getDate()) + "/"
                        + (options.date.getFullYear()) + "/" + (options.date.getHours()) + "/"
                        + (options.date.getMinutes());
            }

            for ( var key in defaults) {
                if (typeof options[key] !== "undefined")
                    defaults[key] = options[key];
            }

            cordova.exec(null, null, "LocalNotification", "add",  new Array(defaults));
};

LocalNotification.prototype.cancel = function(notificationId) {
    cordova.exec(null, null, 'LocalNotification', 'cancel', new Array({
        id : notificationId
    }));
};

LocalNotification.prototype.cancelAll = function() {
    cordova.exec(null, null, 'LocalNotification', 'cancelAll', new Array());
};


var LocalNotification = new LocalNotification();
module.exports = LocalNotification
});

Mise à JOUR #1: je l'ai déjà ajouté le plugin à la plugins.xml fichier:

<plugins>
...
  <plugin name="LocalNotification" value="com.phonegap.plugin.localnotification.LocalNotification"/>
...
</plugins>

J'ai fait les étapes mentionnées ici et remplacer le cassé java expressions comme mentionné ici.

Malheureusement, lorsque je lance l'application, j'obtiens l'erreur suivante (à la Fois dans l'émulateur et périphérique):

09-16 16:46:16.330: E/Console Web(27875): Uncaught ReferenceError:
les plugins n'est pas défini dans le fichier:///android_asset/www/index.html:74

Ce mec a été confronté au même problème mais j'ai référencé le cordova fichier javascript dans mon index.html et sa ne fonctionne toujours pas.

C'est comment mon explorateur de package ressemble (Vous pourriez trouver quelque chose qui manque):
Je ne suis pas sûr si je devrais l'avoir plugins.xml ou ont config.xml et avoir les plugins,
J'ai à la fois juste au cas où

“les plugins n'est pas défini” dans l'Application PhoneGap

Merci d'avance!

OriginalL'auteur Aviran Cohen | 2012-09-16