From d0ffb108b16e5ccf61e7ede5267d1239b142ca8b Mon Sep 17 00:00:00 2001 From: Federico Maccaroni Date: Mon, 31 Jan 2022 11:12:24 -0300 Subject: [PATCH] Cleared Console.WriteLine for iOS push notifications issue (#1739) --- .../PushNotificationListenerService.cs | 21 ++++++++++--------- src/iOS/AppDelegate.cs | 8 ------- .../Services/iOSPushNotificationHandler.cs | 14 ++++++------- .../Services/iOSPushNotificationService.cs | 13 ++++++------ 4 files changed, 23 insertions(+), 33 deletions(-) diff --git a/src/App/Services/PushNotificationListenerService.cs b/src/App/Services/PushNotificationListenerService.cs index 68301cb98..7051b9978 100644 --- a/src/App/Services/PushNotificationListenerService.cs +++ b/src/App/Services/PushNotificationListenerService.cs @@ -30,7 +30,7 @@ namespace Bit.App.Services public async Task OnMessageAsync(JObject value, string deviceType) { - Console.WriteLine($"{TAG} OnMessageAsync called"); + Debug.WriteLine($"{TAG} OnMessageAsync called"); Resolve(); if (value == null) @@ -39,7 +39,7 @@ namespace Bit.App.Services } _showNotification = false; - Console.WriteLine($"{TAG} Message Arrived: {JsonConvert.SerializeObject(value)}"); + Debug.WriteLine($"{TAG} Message Arrived: {JsonConvert.SerializeObject(value)}"); NotificationResponse notification = null; if (deviceType == Device.Android) @@ -56,7 +56,7 @@ namespace Bit.App.Services notification = dataToken.ToObject(); } - Console.WriteLine($"{TAG} - Notification object created: t:{notification?.Type} - p:{notification?.Payload}"); + Debug.WriteLine($"{TAG} - Notification object created: t:{notification?.Type} - p:{notification?.Payload}"); var appId = await _appIdService.GetAppIdAsync(); if (notification?.Payload == null || notification.ContextId == appId) @@ -134,23 +134,24 @@ namespace Bit.App.Services public async Task OnRegisteredAsync(string token, string deviceType) { Resolve(); - Console.WriteLine($"{TAG} - Device Registered - Token : {token}"); + Debug.WriteLine($"{TAG} - Device Registered - Token : {token}"); var isAuthenticated = await _userService.IsAuthenticatedAsync(); if (!isAuthenticated) { - Console.WriteLine($"{TAG} - not auth"); + Debug.WriteLine($"{TAG} - not auth"); return; } var appId = await _appIdService.GetAppIdAsync(); - Console.WriteLine($"{TAG} - app id: {appId}"); try { await _storageService.RemoveAsync(Constants.PushInstallationRegistrationError); await _apiService.PutDeviceTokenAsync(appId, new Core.Models.Request.DeviceTokenRequest { PushToken = token }); - Console.WriteLine($"{TAG} Registered device with server."); + + Debug.WriteLine($"{TAG} Registered device with server."); + await _storageService.SaveAsync(Constants.PushLastRegistrationDateKey, DateTime.UtcNow); if (deviceType == Device.Android) { @@ -159,7 +160,7 @@ namespace Bit.App.Services } catch (ApiException apiEx) { - Console.WriteLine($"{TAG} Failed to register device."); + Debug.WriteLine($"{TAG} Failed to register device."); await _storageService.SaveAsync(Constants.PushInstallationRegistrationError, apiEx.Error?.Message); } @@ -172,12 +173,12 @@ namespace Bit.App.Services public void OnUnregistered(string deviceType) { - Console.WriteLine($"{TAG} - Device Unnregistered"); + Debug.WriteLine($"{TAG} - Device Unnregistered"); } public void OnError(string message, string deviceType) { - Console.WriteLine($"{TAG} error - {message}"); + Debug.WriteLine($"{TAG} error - {message}"); } public bool ShouldShowNotification() diff --git a/src/iOS/AppDelegate.cs b/src/iOS/AppDelegate.cs index 3c834775b..48c1bdd64 100644 --- a/src/iOS/AppDelegate.cs +++ b/src/iOS/AppDelegate.cs @@ -251,36 +251,30 @@ namespace Bit.iOS return base.ContinueUserActivity(application, userActivity, completionHandler); } - const string TAG = "##PUSH NOTIFICATIONS"; public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error) { - Console.WriteLine($"{TAG} FailedToRegisterForRemoteNotifications"); _pushHandler?.OnErrorReceived(error); } public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken) { - Console.WriteLine($"{TAG} RegisteredForRemoteNotifications"); _pushHandler?.OnRegisteredSuccess(deviceToken); } public override void DidRegisterUserNotificationSettings(UIApplication application, UIUserNotificationSettings notificationSettings) { - Console.WriteLine($"{TAG} DidRegisterUserNotificationSettings"); application.RegisterForRemoteNotifications(); } public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action completionHandler) { - Console.WriteLine($"{TAG} DidReceiveRemoteNotification"); _pushHandler?.OnMessageReceived(userInfo); } public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo) { - Console.WriteLine($"{TAG} ReceivedRemoteNotification"); _pushHandler?.OnMessageReceived(userInfo); } @@ -321,8 +315,6 @@ namespace Bit.iOS private void RegisterPush() { - Console.WriteLine($"{TAG} RegisterPush"); - var notificationListenerService = new PushNotificationListenerService(); ServiceContainer.Register( "pushNotificationListenerService", notificationListenerService); diff --git a/src/iOS/Services/iOSPushNotificationHandler.cs b/src/iOS/Services/iOSPushNotificationHandler.cs index 2d17a932b..bfa982432 100644 --- a/src/iOS/Services/iOSPushNotificationHandler.cs +++ b/src/iOS/Services/iOSPushNotificationHandler.cs @@ -12,8 +12,6 @@ namespace Bit.iOS.Services public class iOSPushNotificationHandler : NSObject, IUNUserNotificationCenterDelegate { private const string TokenSetting = "token"; - //private const string DomainName = "iOSPushNotificationService"; - const string TAG = "##PUSH NOTIFICATIONS"; private readonly IPushNotificationListenerService _pushNotificationListenerService; @@ -28,7 +26,7 @@ namespace Bit.iOS.Services { try { - Console.WriteLine($"{TAG} - OnMessageReceived."); + Debug.WriteLine($"{TAG} - OnMessageReceived."); var json = DictionaryToJson(userInfo); var values = JObject.Parse(json); @@ -53,19 +51,19 @@ namespace Bit.iOS.Services public void OnErrorReceived(NSError error) { - Console.WriteLine($"{TAG} - Registration Failed."); + Debug.WriteLine($"{TAG} - Registration Failed."); _pushNotificationListenerService.OnError(error.LocalizedDescription, Device.iOS); } public void OnRegisteredSuccess(NSData token) { - Console.WriteLine($"{TAG} - Successfully Registered."); + Debug.WriteLine($"{TAG} - Successfully Registered."); var hexDeviceToken = BitConverter.ToString(token.ToArray()) .Replace("-", string.Empty) .ToLowerInvariant(); - Console.WriteLine($"{TAG} - Token: {hexDeviceToken}"); + Debug.WriteLine($"{TAG} - Token: {hexDeviceToken}"); UNUserNotificationCenter.Current.Delegate = this; @@ -84,7 +82,7 @@ namespace Bit.iOS.Services [Export("userNotificationCenter:willPresentNotification:withCompletionHandler:")] public void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action completionHandler) { - Console.WriteLine($"{TAG} WillPresentNotification {notification?.Request?.Content?.UserInfo}"); + Debug.WriteLine($"{TAG} WillPresentNotification {notification?.Request?.Content?.UserInfo}"); OnMessageReceived(notification?.Request?.Content?.UserInfo); completionHandler(UNNotificationPresentationOptions.Alert); @@ -93,7 +91,7 @@ namespace Bit.iOS.Services [Export("userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:")] public void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) { - Console.WriteLine($"{TAG} DidReceiveNotificationResponse {response?.Notification?.Request?.Content?.UserInfo}"); + Debug.WriteLine($"{TAG} DidReceiveNotificationResponse {response?.Notification?.Request?.Content?.UserInfo}"); if (response.IsDefaultAction) { diff --git a/src/iOS/Services/iOSPushNotificationService.cs b/src/iOS/Services/iOSPushNotificationService.cs index b7f27b120..c268734c1 100644 --- a/src/iOS/Services/iOSPushNotificationService.cs +++ b/src/iOS/Services/iOSPushNotificationService.cs @@ -1,5 +1,4 @@ -using System; -using System.Diagnostics; +using System.Diagnostics; using System.Threading.Tasks; using Bit.App.Abstractions; using Foundation; @@ -22,7 +21,7 @@ namespace Bit.iOS.Services public async Task RegisterAsync() { - Console.WriteLine($"{TAG} RegisterAsync"); + Debug.WriteLine($"{TAG} RegisterAsync"); var tcs = new TaskCompletionSource(); @@ -31,11 +30,11 @@ namespace Bit.iOS.Services { if (error != null) { - Console.WriteLine($"{TAG} {error}"); + Debug.WriteLine($"{TAG} {error}"); } else { - Console.WriteLine($"{TAG} {granted}"); + Debug.WriteLine($"{TAG} {granted}"); } tcs.SetResult(granted); @@ -43,14 +42,14 @@ namespace Bit.iOS.Services if (await tcs.Task) { - Console.WriteLine($"{TAG} RegisterForRemoteNotifications"); + Debug.WriteLine($"{TAG} RegisterForRemoteNotifications"); UIApplication.SharedApplication.RegisterForRemoteNotifications(); } } public Task UnregisterAsync() { - Console.WriteLine($"{TAG} UnregisterAsync"); + Debug.WriteLine($"{TAG} UnregisterAsync"); UIApplication.SharedApplication.UnregisterForRemoteNotifications(); // TODO: unregister call