mirror of
https://github.com/bitwarden/mobile
synced 2026-01-05 18:13:36 +00:00
Added Logs for PN registration checks (#1731)
This commit is contained in:
committed by
GitHub
parent
f1ccbbc105
commit
37f4439892
@@ -251,30 +251,36 @@ 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);
|
||||
}
|
||||
|
||||
@@ -315,6 +321,8 @@ namespace Bit.iOS
|
||||
|
||||
private void RegisterPush()
|
||||
{
|
||||
Console.WriteLine($"{TAG} RegisterPush");
|
||||
|
||||
var notificationListenerService = new PushNotificationListenerService();
|
||||
ServiceContainer.Register<IPushNotificationListenerService>(
|
||||
"pushNotificationListenerService", notificationListenerService);
|
||||
|
||||
@@ -12,7 +12,9 @@ namespace Bit.iOS.Services
|
||||
public class iOSPushNotificationHandler : NSObject, IUNUserNotificationCenterDelegate
|
||||
{
|
||||
private const string TokenSetting = "token";
|
||||
private const string DomainName = "iOSPushNotificationService";
|
||||
//private const string DomainName = "iOSPushNotificationService";
|
||||
|
||||
const string TAG = "##PUSH NOTIFICATIONS";
|
||||
|
||||
private readonly IPushNotificationListenerService _pushNotificationListenerService;
|
||||
|
||||
@@ -26,6 +28,8 @@ namespace Bit.iOS.Services
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.WriteLine($"{TAG} - OnMessageReceived.");
|
||||
|
||||
var json = DictionaryToJson(userInfo);
|
||||
var values = JObject.Parse(json);
|
||||
var keyAps = new NSString("aps");
|
||||
@@ -49,19 +53,19 @@ namespace Bit.iOS.Services
|
||||
|
||||
public void OnErrorReceived(NSError error)
|
||||
{
|
||||
Debug.WriteLine("{0} - Registration Failed.", DomainName);
|
||||
Console.WriteLine($"{TAG} - Registration Failed.");
|
||||
_pushNotificationListenerService.OnError(error.LocalizedDescription, Device.iOS);
|
||||
}
|
||||
|
||||
public void OnRegisteredSuccess(NSData token)
|
||||
{
|
||||
Debug.WriteLine("{0} - Successfully Registered.", DomainName);
|
||||
Console.WriteLine($"{TAG} - Successfully Registered.");
|
||||
|
||||
var hexDeviceToken = BitConverter.ToString(token.ToArray())
|
||||
.Replace("-", string.Empty)
|
||||
.ToLowerInvariant();
|
||||
|
||||
Debug.WriteLine("{0} - Token: {1}", DomainName, hexDeviceToken);
|
||||
Console.WriteLine($"{TAG} - Token: {hexDeviceToken}");
|
||||
|
||||
UNUserNotificationCenter.Current.Delegate = this;
|
||||
|
||||
@@ -80,7 +84,7 @@ namespace Bit.iOS.Services
|
||||
[Export("userNotificationCenter:willPresentNotification:withCompletionHandler:")]
|
||||
public void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler)
|
||||
{
|
||||
Debug.WriteLine($"{DomainName} WillPresentNotification {notification?.Request?.Content?.UserInfo}");
|
||||
Console.WriteLine($"{TAG} WillPresentNotification {notification?.Request?.Content?.UserInfo}");
|
||||
|
||||
OnMessageReceived(notification?.Request?.Content?.UserInfo);
|
||||
completionHandler(UNNotificationPresentationOptions.Alert);
|
||||
@@ -89,7 +93,7 @@ namespace Bit.iOS.Services
|
||||
[Export("userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:")]
|
||||
public void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler)
|
||||
{
|
||||
Debug.WriteLine($"{DomainName} DidReceiveNotificationResponse {response?.Notification?.Request?.Content?.UserInfo}");
|
||||
Console.WriteLine($"{TAG} DidReceiveNotificationResponse {response?.Notification?.Request?.Content?.UserInfo}");
|
||||
|
||||
if (response.IsDefaultAction)
|
||||
{
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace Bit.iOS.Services
|
||||
public class iOSPushNotificationService : NSObject, IPushNotificationService, IUNUserNotificationCenterDelegate
|
||||
{
|
||||
private const string TokenSetting = "token";
|
||||
const string TAG = "##PUSH NOTIFICATIONS";
|
||||
|
||||
public Task<string> GetTokenAsync()
|
||||
{
|
||||
@@ -21,6 +22,8 @@ namespace Bit.iOS.Services
|
||||
|
||||
public async Task RegisterAsync()
|
||||
{
|
||||
Console.WriteLine($"{TAG} RegisterAsync");
|
||||
|
||||
var tcs = new TaskCompletionSource<bool>();
|
||||
|
||||
var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;
|
||||
@@ -28,11 +31,11 @@ namespace Bit.iOS.Services
|
||||
{
|
||||
if (error != null)
|
||||
{
|
||||
Debug.WriteLine($"Push Notifications {error}");
|
||||
Console.WriteLine($"{TAG} {error}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.WriteLine($"Push Notifications {granted}");
|
||||
Console.WriteLine($"{TAG} {granted}");
|
||||
}
|
||||
|
||||
tcs.SetResult(granted);
|
||||
@@ -40,12 +43,15 @@ namespace Bit.iOS.Services
|
||||
|
||||
if (await tcs.Task)
|
||||
{
|
||||
Console.WriteLine($"{TAG} RegisterForRemoteNotifications");
|
||||
UIApplication.SharedApplication.RegisterForRemoteNotifications();
|
||||
}
|
||||
}
|
||||
|
||||
public Task UnregisterAsync()
|
||||
{
|
||||
Console.WriteLine($"{TAG} UnregisterAsync");
|
||||
|
||||
UIApplication.SharedApplication.UnregisterForRemoteNotifications();
|
||||
// TODO: unregister call
|
||||
// _pushNotificationListener.OnUnregistered(Device.iOS);
|
||||
|
||||
Reference in New Issue
Block a user