无法阅读Property' email'在phonegap中未定义

时间:2014-06-19 08:31:25

标签: javascript android cordova phonegap-plugins phonegap-build

现在已经有好几天了,我仍在努力在我的phonegap项目中使用第三方插件。我使用phonegap CLI(版本3.4)通过以下命令安装了插件:

phonegap local plugin add <git repo path>

插件已成功添加,我可以看到src文件夹中的包。我还通过这个CLI命令为/droid建立了项目

phonegap build android

这也会返回成功的回复。我也在config.xml中输入gap:plugin但没有任何作用。我得到的只是LogCat中的这个错误

[INFO:CONSOLE(265)] "Uncaught TypeError: Cannot read property 'email' of undefined"

仅供参考:我正在尝试使用this插件。这就是我尝试在我的js文件中使用此插件的方式

window.plugin.email.isServiceAvailable(
            function (isAvailable) {
                alert(isAvailable);
            }
        );

这是插件的cordova_plugins.xml中的条目:

{
        "file": "plugins/de.appplant.cordova.plugin.email-composer/www/email_composer.js",
        "id": "de.appplant.cordova.plugin.email-composer.EmailComposer",
        "clobbers": [
            "plugin.email"
        ]
    }

这就是email_composer.js中代码的样子:

cordova.define("de.appplant.cordova.plugin.email-composer.EmailComposer", function(require, exports, module) { 

var EmailComposer = function () {

};

EmailComposer.prototype = {
/**
 * Displays the email composer pre-filled with data.
 *
 * @param {Object} options
 *      Different properties of the email like the body, subject
 * @param {Function} callback
 *      A callback function to be called with the result
 * @param {Object?} scope
 *      The scope of the callback
 */
open: function (options, callback, scope) {
    var callbackFn = this.createCallbackFn(callback, scope),
        options    = options || {};

    var defaults = {
        subject:     null,
        body:        null,
        to:          null,
        cc:          null,
        bcc:         null,
        attachments: null,
        isHtml:      true
    }

    for (var key in defaults) {
        if (options[key] !== undefined) {
            defaults[key] = options[key];
        } else {
            console.log('EmailComposer plugin: unknown property "' + key + '"');
        }
    }

    cordova.exec(callbackFn, null, 'EmailComposer', 'open', [options]);
},

/**
 * Alias für `open()`.
 */
openDraft: function () {
    this.open.apply(this, arguments);
},

/**
 * Verifies if sending emails is supported on the device.
 *
 * @param {Function} callback
 *      A callback function to be called with the result
 * @param {Object} scope
 *      The scope of the callback
 */
isServiceAvailable: function (callback, scope) {
    var callbackFn = this.createCallbackFn(callback, scope);

    cordova.exec(callbackFn, null, 'EmailComposer', 'isServiceAvailable', []);
},

/**
 * @private
 *
 * Creates a callback, which will be executed within a specific scope.
 *
 * @param {Function} callbackFn
 *      The callback function
 * @param {Object} scope
 *      The scope for the function
 *
 * @return {Function}
 *      The new callback function
 */
createCallbackFn: function (callbackFn, scope) {
    return function () {
        if (typeof callbackFn == 'function') {
            callbackFn.apply(scope || this, arguments);
        }
    }
}
};

var plugin = new EmailComposer();

module.exports = plugin;
});

请注意,当我运行add plugin命令时会自动生成此email_composer.js文件。我没有修改它。

0 个答案:

没有答案