您好我正在尝试将本地通知添加到 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)
}
索引.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>
这是我的错误:
控制台(5501):未捕获的 ReferenceError:模块未在文件中定义:///android_asset/www/local-notification.js:87