简体   繁体   English

phonegap本地通知错误

[英]phonegap local notification error

Hi Im trying to add local notifications to a project in android phonegapp and I have this error, Im using this plugin https://github.com/katzer/cordova-plugin-local-notifications : 嗨,我正在尝试将本地通知添加到android phonegapp中的项目中,但我遇到此错误,我正在使用此插件https://github.com/katzer/cordova-plugin-local-notifications

var LocalNotification = function () {

};

LocalNotification.prototype = {
/**
 * Fügt einen neuen Eintrag zur Registry hinzu.
 *
 * @param {Object} options
 * @return {Number} Die ID der Notification
 */
add: function (options) {
    var defaults = {
        date:       new Date(),
        message:    '',
        title:      '',
        badge:      0,
        id:         0,
        repeat:     '',
        background: '',
        foreground: ''
    };

    switch (device.platform) {
        case 'Android':
            defaults.icon = 'icon';
            defaults.sound = 'TYPE_NOTIFICATION'; break;
        case 'iOS':
            defaults.sound = ''; break;
        case 'WinCE': case 'Win32NT':
            defaults.smallImage = null;
            defaults.image = null;
            defaults.wideImage = null;
    };

    var callbackFn = function (cmd) {
        eval(cmd);
    };

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

    if (defaults.id) {
        defaults.id = defaults.id.toString();
    }

    if (typeof defaults.date == 'object') {
        defaults.date = Math.round(defaults.date.getTime()/1000);
    }

    cordova.exec(callbackFn, null, 'LocalNotification', 'add', [defaults]);

    return defaults.id;
},

/**
 * Entfernt die angegebene Notification.
 *
 * @param {String} id
 */
cancel: function (id) {
    cordova.exec(null, null, 'LocalNotification', 'cancel', [id.toString()]);
},

/**
 * Entfernt alle registrierten Notifications.
 */
 cancelAll: function () {
        cordova.exec(null, null, 'LocalNotification', 'cancelAll', []);
    }
};

var plugin = new LocalNotification();

module.exports = plugin;

var now                  = new Date().getTime(),
_60_seconds_from_now = new Date(now + 60*1000);

 LocalNotification.add({
 id:         1,                       // is converted to a string
 date:       _60_seconds_from_now,
 message:    'Hello world!',
 title:      'Check that out!',
 repeat:     'weekly',                // will fire every week on this day
 foreground: 'foreground',
 background: 'background'
});

function foreground (id) {
    console.log('I WAS RUNNING ID='+id)
}

function background (id) {
    console.log('I WAS IN THE BACKGROUND ID='+id)
}

index.html index.html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <title>Hello World</title>
    </head>
    <body>
        <div class="app">
            <h1>PhoneGap</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p class="event received">Device is Ready</p>
            </div>
        </div>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
        <script type="text/javascript" src="local-notification.js"></script>

        <script type="text/javascript">
            app.initialize();

        </script>
    </body>
</html>

This is my error: 这是我的错误:

Console(5501): Uncaught ReferenceError: module is not defined at file:///android_asset/www/local-notification.js:87 控制台(5501):未捕获的ReferenceError:未在file:///android_asset/www/local-notification.js:87定义模块

Your js file is missing. 您的js文件丢失。

Did you add the plugin with Cordovas CLI? 您是否使用Cordovas CLI添加了插件?

Sometimes Cordova does not add the js or objective-c files to the project. 有时,Cordova不会将js或Objective-c文件添加到项目中。

Check if your local-notification.js is in the folder and is properly linked to (it should also appear in www/plugins/com.name.pluginname.plugin/www/*.js Also check the existence of the .h & .m files. 检查您的local-notification.js是否在文件夹中并已正确链接(它也应该出现在www / plugins / com.name.pluginname.plugin / www / *。js中,还要检查.h &的存在.m文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM