我想創建帶有通知的Ionic應用程序。 我安裝PushPlugin,這是我的控制器:離子 - 推送通知 - 'pushNotification'的undefined
.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
});
})
});
通過離子發球我有錯誤運行後:
ng-cordova.js:6180 Uncaught TypeError: Cannot read property 'pushNotification' of undefined
我找到了一些解決方案,所以我修改我的代碼:
的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
});
}
})
});
現在,我已經有了:
Uncaught ReferenceError: cordova is not defined
我很困惑,怎麼辦好呢。
插件列表:
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"
嘗試此鏈接https://devdactic.com/ionic-push-notifications-guide/ –