diff --git a/src/js/controllers/preferencesNotifications.js b/src/js/controllers/preferencesNotifications.js index cf8c5a979..5cf80a4af 100644 --- a/src/js/controllers/preferencesNotifications.js +++ b/src/js/controllers/preferencesNotifications.js @@ -13,9 +13,13 @@ angular.module('copayApp.controllers').controller('preferencesNotificationsContr $scope.PNEnabledByUser = true; $scope.isIOSApp = isIOS && isCordova; if ($scope.isIOSApp) { - PushNotification.hasPermission(function(data) { - $scope.PNEnabledByUser = data.isEnabled; - }); + try { + PushNotification.hasPermission(function(data) { + $scope.PNEnabledByUser = data.isEnabled; + }); + } catch(e) { + $log.error(e); + }; } $scope.pushNotifications = { @@ -24,6 +28,7 @@ angular.module('copayApp.controllers').controller('preferencesNotificationsContr }; $scope.pushNotificationsChange = function() { + if (!$scope.pushNotifications) return; var opts = { pushNotifications: { enabled: $scope.pushNotifications.value diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 5a6cfc88e..659f9dd8f 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -318,6 +318,8 @@ angular.module('copayApp.services') var defaults = configService.getDefaults(); var push = pushNotificationsService.init(root.wallet); + if (!push) return; + push.on('notification', function(data) { if (!data.additionalData.foreground) { $log.debug('Push notification event: ', data.message); diff --git a/src/js/services/pushNotificationsService.js b/src/js/services/pushNotificationsService.js index 57d9d5ddd..904ae4246 100644 --- a/src/js/services/pushNotificationsService.js +++ b/src/js/services/pushNotificationsService.js @@ -11,7 +11,12 @@ angular.module('copayApp.services') root.init = function(walletsClients) { var defaults = configService.getDefaults(); - var push = PushNotification.init(defaults.pushNotifications.config); + try { + var push = PushNotification.init(defaults.pushNotifications.config); + } catch(e) { + $log.error(e); + return; + }; push.on('registration', function(data) { $log.debug('Starting push notification registration');