【发布时间】:2016-05-27 07:54:49
【问题描述】:
我想创建带有通知的 Ionic 应用程序。 我安装了 PushPlugin,这是我的控制器:
.controller('MainCtrl', function($scope,$ionicPlatform,$cordovaPush) {
$ionicPlatform.ready(function () {
var androidConfig = {
"senderID": "ID"
};
$cordovaPush.register(androidConfig).then(function(result) {
// Success
console.log(result);
}, function(err) {
// Error
});
})
});
通过 ionic serve 运行后出现错误:
ng-cordova.js:6180 未捕获类型错误:无法读取属性 未定义的'pushNotification'
我找到了一些解决方案,所以我修改了我的代码:
index.html(仅头部标签):
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="css/ionic.app.css" rel="stylesheet">
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="cordova.js"></script>
<!-- copy from plugin www folder -->
<script src="js/libs/PushNotification.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
</head>
和我的控制器:
.controller('MainCtrl', function($scope,$ionicPlatform,$cordovaPush) {
$ionicPlatform.ready(function () {
var androidConfig = {
"senderID": "ID"
};
if (window.plugins && window.plugins.pushNotification){
console.log("plugins"); //it displays
$cordovaPush.register(androidConfig).then(function(result) {
// Success
console.log(result);
}, function(err) {
// Error
});
}
})
});
现在,我有:
未捕获的引用错误:cordova 未定义
我很困惑,如何运行它。
插件列表:
com.phonegap.plugins.PushPlugin 2.5.0 "PushPlugin"
cordova-plugin-console 1.0.3 "Console"
cordova-plugin-device 1.1.2 "Device"
cordova-plugin-splashscreen 3.2.2 "Splashscreen"
cordova-plugin-statusbar 2.1.3 "StatusBar"
cordova-plugin-whitelist 1.2.2 "Whitelist"
ionic-plugin-keyboard 2.2.0 "Keyboard"
【问题讨论】:
标签: cordova ionic-framework push-notification