From fdc03a6f295bb240578a504d2501f762bdc8c650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Wed, 23 Dec 2015 12:29:46 -0300 Subject: [PATCH] push notifications --- cordova/build.sh | 6 +++ src/js/controllers/index.js | 48 ++++++++++++++++++++- src/js/services/pushNotificationsService.js | 14 ++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 src/js/services/pushNotificationsService.js diff --git a/cordova/build.sh b/cordova/build.sh index 40d6916d4..c4be3d920 100755 --- a/cordova/build.sh +++ b/cordova/build.sh @@ -106,6 +106,12 @@ if [ ! -d $PROJECT ]; then cordova plugin add cordova-plugin-customurlscheme --variable URL_SCHEME=bitcoin checkOK + cordova plugin add phonegap-plugin-push@1.2.3 + checkOK + + cordova plugin add https://github.com/EddyVerbruggen/LaunchMyApp-PhoneGap-Plugin.git --variable URL_SCHEME=bitcoin + checkOK + cordova plugin add cordova-plugin-inappbrowser checkOK diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index e79055aba..c6047c022 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, lodash, go, profileService, configService, isCordova, rateService, storageService, addressService, gettext, gettextCatalog, amMoment, nodeWebkit, addonManager, feeService, isChromeApp, bwsError, txFormatService, uxLanguage, $state, glideraService, isMobile, addressbookService) { +angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, pushNotificationsService, lodash, go, profileService, configService, isCordova, rateService, storageService, addressService, gettext, gettextCatalog, amMoment, nodeWebkit, addonManager, feeService, isChromeApp, bwsError, txFormatService, uxLanguage, $state, glideraService, isMobile, addressbookService) { var self = this; var SOFT_CONFIRMATION_LIMIT = 12; self.isCordova = isCordova; @@ -11,6 +11,52 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.updatingTxHistory = {}; self.prevState = 'walletHome'; + document.addEventListener('deviceready', function() { + + var push = PushNotification.init({ + android: { + senderID: "959259672122" + }, + ios: { + alert: "true", + badge: true, + sound: 'false' + }, + windows: {} + }); + + push.on('registration', function(data) { + var opts = {}; + opts.user = "Gabriel"; + opts.type = "android"; + opts.token = data.registrationId; + pushNotificationsService.subscribe(opts).then(function(response) { + console.log(response); + }, + function(err) { + console.log(err); + }); + }); + + push.on('notification', function(data) { + console.log("notification event"); + alert(data.message); + + // data.message, + // data.title, + // data.count, + // data.sound, + // data.image, + // data.additionalData + }); + + push.on('error', function(e) { + console.log("error pushhhhhh"); + alert(e.message); + }); + + }); + function strip(number) { return (parseFloat(number.toPrecision(12))); }; diff --git a/src/js/services/pushNotificationsService.js b/src/js/services/pushNotificationsService.js new file mode 100644 index 000000000..78e186650 --- /dev/null +++ b/src/js/services/pushNotificationsService.js @@ -0,0 +1,14 @@ + 'use strict'; + angular.module('copayApp.services') + .factory('pushNotificationsService', function($http) { + var root = {}; + + //"APA91bHCysW7fzE_ks5HPOu2BGr0G7T-aD5SPfzaSGIKuhp82gFUcopVPPck8EfnxgHyK_3QJ9FdFS8H2mjAILDv3jdrH6slJzmCwoszya9XdJz4Uv-cxkLDYXb7z086TD3uPgSLnMUO" + + root.subscribe = function(opts) { + return $http.post('http://192.168.1.120:8000/subscribe', opts); + } + + return root; + + });