Merge pull request #3789 from gabrielbazan7/fix/registrationPushControl
adding control for non ios and android device in pushnotifications registration
This commit is contained in:
commit
189db76999
3 changed files with 34 additions and 24 deletions
|
|
@ -103,13 +103,10 @@ if [ ! -d $PROJECT ]; then
|
|||
cordova plugin add cordova-plugin-statusbar
|
||||
checkOK
|
||||
|
||||
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
|
||||
cordova plugin add cordova-plugin-customurlscheme --variable URL_SCHEME=bitcoin
|
||||
checkOK
|
||||
|
||||
cordova plugin add cordova-plugin-inappbrowser
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
var SOFT_CONFIRMATION_LIMIT = 12;
|
||||
self.isCordova = isCordova;
|
||||
self.isChromeApp = isChromeApp;
|
||||
self.usePushNotifications = isMobile.iOS() || isMobile.Android();
|
||||
self.isSafari = isMobile.Safari();
|
||||
self.onGoingProcess = {};
|
||||
self.historyShowLimit = 10;
|
||||
|
|
@ -12,13 +13,11 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
self.prevState = 'walletHome';
|
||||
|
||||
document.addEventListener('deviceready', function() {
|
||||
if (isMobile.Android() || isMobile.iOS()) {
|
||||
storageService.getDeviceToken(function(err, token) {
|
||||
$timeout(function() {
|
||||
if (!token) pushNotificationsService.pushNotificationsInit();
|
||||
}, 5000);
|
||||
});
|
||||
}
|
||||
storageService.getDeviceToken(function(err, token) {
|
||||
$timeout(function() {
|
||||
if (!token) pushNotificationsService.pushNotificationsInit();
|
||||
}, 5000);
|
||||
});
|
||||
});
|
||||
|
||||
function strip(number) {
|
||||
|
|
@ -1075,11 +1074,12 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
});
|
||||
};
|
||||
|
||||
self.setUxLanguage = function() {
|
||||
self.setUxLanguage = function(cb) {
|
||||
uxLanguage.update(function(lang) {
|
||||
var userLang = lang;
|
||||
self.defaultLanguageIsoCode = userLang;
|
||||
self.defaultLanguageName = uxLanguage.getName(userLang);
|
||||
if (cb) return cb();
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -1285,13 +1285,17 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
});
|
||||
|
||||
$rootScope.$on('Local/SubscribeNotifications', function(event) {
|
||||
|
||||
pushNotificationsService.enableNotifications();
|
||||
|
||||
});
|
||||
|
||||
$rootScope.$on('Local/UnsubscribeNotifications', function(event, walletId, cb) {
|
||||
pushNotificationsService.unsubscribe(walletId, function(err, response) {
|
||||
if (err) $log.warn('Error: ' + err.code);
|
||||
$log.debug('Unsubscribed: ' + response);
|
||||
if (!self.usePushNotifications) return cb();
|
||||
|
||||
pushNotificationsService.unsubscribe(walletId, function(err) {
|
||||
if (err) $log.warn('Subscription error: ' + err.code);
|
||||
else $log.debug('Unsubscribed from push notifications service');
|
||||
return cb();
|
||||
});
|
||||
});
|
||||
|
|
@ -1430,7 +1434,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
self.noFocusedWallet = true;
|
||||
self.isComplete = null;
|
||||
self.walletName = null;
|
||||
self.setUxLanguage(function() {});
|
||||
self.setUxLanguage();
|
||||
profileService.isDisclaimerAccepted(function(v) {
|
||||
if (v) {
|
||||
go.path('import');
|
||||
|
|
@ -1440,7 +1444,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
|||
});
|
||||
|
||||
$rootScope.$on('Local/NewFocusedWallet', function() {
|
||||
self.setUxLanguage(function() {});
|
||||
self.setUxLanguage();
|
||||
self.setFocusedWallet();
|
||||
self.debounceUpdateHistory();
|
||||
self.isDisclaimerAccepted();
|
||||
|
|
|
|||
|
|
@ -3,8 +3,11 @@ angular.module('copayApp.services')
|
|||
.factory('pushNotificationsService', function($http, $log, isMobile, profileService, storageService, configService, lodash) {
|
||||
var root = {};
|
||||
var defaults = configService.getDefaults();
|
||||
var usePushNotifications = isMobile.iOS() || isMobile.Android();
|
||||
|
||||
root.pushNotificationsInit = function() {
|
||||
if (!usePushNotifications) return;
|
||||
|
||||
var push = PushNotification.init(defaults.pushNotifications.config);
|
||||
|
||||
push.on('registration', function(data) {
|
||||
|
|
@ -31,29 +34,34 @@ angular.module('copayApp.services')
|
|||
};
|
||||
|
||||
root.enableNotifications = function() {
|
||||
if (!usePushNotifications) return;
|
||||
|
||||
storageService.getDeviceToken(function(err, token) {
|
||||
lodash.forEach(profileService.getWallets('testnet'), function(wallet) {
|
||||
var opts = {};
|
||||
opts.type = isMobile.iOS() ? "ios" : isMobile.Android() ? "android" : null;
|
||||
opts.token = token;
|
||||
root.subscribe(opts, wallet.id, function(err, response) {
|
||||
if (err) $log.warn('Error: ' + err.code);
|
||||
$log.debug('Suscribed to push notifications service: ' + JSON.stringify(response));
|
||||
if (err) $log.warn('Subscription error: ' + err.code);
|
||||
else $log.debug('Subscribed to push notifications service: ' + JSON.stringify(response));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
root.disableNotifications = function() {
|
||||
if (!usePushNotifications) return;
|
||||
|
||||
lodash.forEach(profileService.getWallets('testnet'), function(wallet) {
|
||||
root.unsubscribe(wallet.id, function(err, response) {
|
||||
if (err) $log.warn('Error: ' + err.code);
|
||||
$log.debug('Unsubscribed from push notifications service');
|
||||
root.unsubscribe(wallet.id, function(err) {
|
||||
if (err) $log.warn('Subscription error: ' + err.code);
|
||||
else $log.debug('Unsubscribed from push notifications service');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
root.subscribe = function(opts, walletId, cb) {
|
||||
|
||||
var walletClient = profileService.getClient(walletId);
|
||||
walletClient.pushNotificationsSubscribe(opts, function(err, resp) {
|
||||
if (err) return cb(err);
|
||||
|
|
@ -62,10 +70,11 @@ angular.module('copayApp.services')
|
|||
}
|
||||
|
||||
root.unsubscribe = function(walletId, cb) {
|
||||
|
||||
var walletClient = profileService.getClient(walletId);
|
||||
walletClient.pushNotificationsUnsubscribe(function(err, resp) {
|
||||
walletClient.pushNotificationsUnsubscribe(function(err) {
|
||||
if (err) return cb(err);
|
||||
return cb(null, resp);
|
||||
return cb(null);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue