Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var xxx = angular.module('starter', ['ionic', 'ngCordova'])
- xxx.run(function ($ionicPlatform, $cordovaPush) {
- $ionicPlatform.ready(function () {
- if (window.cordova && window.cordova.plugins.Keyboard) {
- cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
- }
- if (window.StatusBar) {
- StatusBar.styleDefault();
- }
- var androidConfig = {
- "senderID": "5757xxxxxxx",
- };
- document.addEventListener("deviceready", function () {
- $cordovaPush.register(androidConfig).then(function (result) {
- alert(result);
- }, function (err) {
- alert(err);
- })
- $rootScope.$on('$cordovaPush:notificationReceived', function (event, notification) {
- switch (notification.event) {
- case 'registered':
- if (notification.regid.length > 0) {
- alert('registration ID = ' + notification.regid);
- }
- break;
- case 'message':
- // this is the actual push notification. its format depends on the data model from the push server
- alert('message = ' + notification.message + ' msgCount = ' + notification.msgcnt);
- break;
- case 'error':
- alert('GCM error = ' + notification.msg);
- break;
- default:
- alert('An unknown GCM event has occurred');
- break;
- }
- });
- // WARNING: dangerous to unregister (results in loss of tokenID)
- $cordovaPush.unregister(options).then(function (result) {
- // Success!
- }, function (err) {
- // Error
- })
- }, false)
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement