Я добавил плагин для подключения к телефону и ngcordova. ngcordova.js
был импортирован до cordova.js
Я получаю ошибку $window.plugin not defined
в браузере, который, как я полагаю, ожидается. Но я получаю ошибку cannot read property register of undefined
в приложении, что означает, что $cordovaPush
не определено.Ионное приложение - CordovaPush не работает
Я посмотрел на this учебнике и пытаюсь реализовать же
angular
.module('init')
.run(function($ionicPlatform, $rootScope, $state, $cordovaPush, $cordovaToast){
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
window.StatusBar.styleDefault();
}
registerForPush();
function registerForPush(){
try {
var config = {};
//register for push notifications
if (ionic.Platform.isAndroid()) {
config = {
"senderID": "1232"
};
}else if (ionic.Platform.isIOS()) {
config = {
"badge": "true",
"sound": "true",
"alert": "true"
}
}
$cordovaPush.register(config).then(function (result) {
alert("Register success " + result);
$cordovaToast.showShortCenter('Registered for push notifications');
// ** NOTE: Android regid result comes back in the pushNotificationReceived, only iOS returned here
if (ionic.Platform.isIOS()) {
//register
}
}, function (err) {
console.log("Register error " + err)
});
}
catch(err) {
alert(err.message);
}
}
// Notification Received
$rootScope.$on('$cordovaPush:notificationReceived', function (event, notification) {
alert(JSON.stringify([notification]));
if (ionic.Platform.isAndroid()) {
if (notification.event == "registered") {
alert("android notification received token - " + notification.regid);
}
}
else if (ionic.Platform.isIOS()) {
alert("ios notification received");
}
});
document.addEventListener('resume', function() {
$rootScope.$broadcast('resume');
});
document.addEventListener('pause', function() {
$rootScope.$broadcast('pause');
});
document.addEventListener('offline', function() {
$rootScope.$broadcast('offline');
});
document.addEventListener('online', function() {
$rootScope.$broadcast('online');
});
window.addEventListener('batterystatus', function (status) {
$rootScope.$broadcast('batterystatus', status);
});
});
});
Я смущен. что вы подразумеваете, не используя Plugin-push? Можете ли вы добавить пример кода – Coder
Я пытаюсь использовать собственные уведомления, а не ионный push! – Coder