Cleared Console.WriteLine for iOS push notifications issue (#1739)

This commit is contained in:
Federico Maccaroni 2022-01-31 11:12:24 -03:00 committed by GitHub
parent c0c893fd59
commit d0ffb108b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 33 deletions

View File

@ -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<NotificationResponse>();
}
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()

View File

@ -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<UIBackgroundFetchResult> 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<IPushNotificationListenerService>(
"pushNotificationListenerService", notificationListenerService);

View File

@ -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<UNNotificationPresentationOptions> 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)
{

View File

@ -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<bool>();
@ -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