您好我试图将本地通知添加到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
<!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:模块未在file:///android_asset/www/local-notification.js中定义:87
答案 0 :(得分:1)
您的js文件丢失了。
您是否使用Cordovas CLI添加插件?
有时Cordova不会将js或objective-c文件添加到项目中。
检查你的local-notification.js是否在文件夹中并且是否正确链接(它也应该出现在www / plugins / com.name.pluginname.plugin / www / * .js
同时检查.h
&amp;的存在性。 .m
个文件。