Hi,
I try to Sending Push Notification with Ionic.io.
I using this same code Ionic Docs - Ionic Documentation
But, when I run my app, I have this error :
ionic.io.bundle.min.js:3 Uncaught TypeError: Cannot read property ‘init’ of undefined
This is my code:
'Use Strict';
angular.module('App', ['ionic', 'ionic.service.core', 'ngCordova', 'ngCordovaOauth', 'ngStorage', 'ngMessages', 'firebase', 'ionic-datepicker', 'ionic-timepicker', 'monospaced.elastic', 'angularMoment', 'jrCrop']) //, 'ionic.service.push', 'ionic.service.core'
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('menu', {
url: "/menu",
abstract: true,
templateUrl: "views/menu/menu.html",
controller: 'menuController'
})
.state('login', {
url: '/login',
templateUrl: 'views/login/login.html',
controller:'loginController'
})
.state('forgot', {
url: '/forgot',
templateUrl: 'views/forgot/forgot.html',
controller:'forgotController'
})
.state('register', {
url: '/register',
templateUrl: 'views/register/register.html',
controller:'registerController'
})
.state('menu.home', {
url: '/home',
views: {
'menuContent': {
templateUrl: 'views/home/home.html',
controller: 'homeController'
}
}
})
;
$urlRouterProvider.otherwise("/login");
})
.constant('FURL', 'https://xxxxxxxxxfirebaseIO.com/')
.run(function ($ionicPlatform, $cordovaSQLite, $cordovaGeolocation, geoLocation, $rootScope, $ionicPopup) {
$ionicPlatform.ready(function () {
var push = new Ionic.Push({
"debug": true
});
push.register(function (token) {
console.log("Device token:", token.token);
push.saveToken(token); // persist the token in the Ionic Platform
});
navigator.geolocation.getCurrentPosition(function (location) {
console.log('[GEOLOCAL JS1] Location');
},
function (error) {
console.log('[GEOLOCAL JS1] error with GPS: error.code: ' + error.code + ' Message: ' + error.message);
});
$cordovaGeolocation
.getCurrentPosition()
.then(function (position) {
geoLocation.setGeolocation(position.coords.latitude, position.coords.longitude);
}, function (err) {
// you need to enhance that point
$ionicPopup.alert({
title: 'Ooops...',
template: err.message
});
// geoLocation.setGeolocation(defaultLocalisation.latitude, defaultLocalisation.longitude)
});
// begin a watch
var watch = $cordovaGeolocation.watchPosition({
frequency: 1000,
timeout: 3000,
enableHighAccuracy: false
}).then(function () {
}, function (err) {
// you need to enhance that point
// geoLocation.setGeolocation(defaultLocalisation.latitude, defaultLocalisation.longitude);
}, function (position) {
geoLocation.setGeolocation(position.coords.latitude, position.coords.longitude);
// broadcast this event on the rootScope
$rootScope.$broadcast('location:change', geoLocation.getGeolocation());
}
);
// 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) {
StatusBar.styleDefault();
}
if (window.cordova) {
db = $cordovaSQLite.openDB("my.db");
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS user (id integer primary key, email text, password text, lastUser INTEGER DEFAULT 0)");
} else {
db = window.openDatabase("my.db", '1', 'my', 1024 * 1024 * 100); // browser
}
});
})
and my index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src 'self' 'unsafe-inline' *">
<title></title>
<!-- compiled css output -->
<link href="css/ionic.app.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<link href="css/jr-crop.scss" rel="stylesheet">
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="lib/ionic-platform-web-client/dist/ionic.io.bundle.min.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="lib/ngCordova/dist/ng-cordova.min.js"></script>
<!-- Cordova is bootstrapped by ionic-platform-web-client, uncomment this if you remove ionic-platform-web-client... -->
<!-- <script src="cordova.js"></script> -->
<script src="lib/angular-google-maps/dist/angular-google-maps.min.js"></script>
<script src="lib/lodash/dist/lodash.min.js"></script>
<script src="lib/ngstorage/ngStorage.min.js"></script>
<script src="lib/firebase/firebase.js"></script>
<script src="lib/angularfire/dist/angularfire.min.js"></script>
<script src="lib/angular-messages/angular-messages.min.js"></script>
<script src="lib/moment/moment.js"></script>
<script src="lib/angular-moment/angular-moment.js"></script>
<script src="lib/moment/locale/fr.js"></script>
<script src="lib/jr-crop/src/jr-crop.js"></script>
<script src="lib/ionic-datepicker/dist/ionic-datepicker.bundle.min.js"></script>
<script src="lib/ionic-timepicker/dist/ionic-timepicker.bundle.min.js"></script>
<script src="lib/ng-cordova-oauth/dist/ng-cordova-oauth.min.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/services/auth.js"></script>
<script src="js/services/utils.js"></script>
</head>
<body ng-app="App">
<ion-nav-view></ion-nav-view>
</body>
</html>
how I can solve this problem?