mirror of
https://github.com/bitwarden/mobile
synced 2025-12-14 23:33:34 +00:00
Fixes for iOS push notifications (#1708)
* WIP Fixes for iOS push notifications * WIP Fixes for iOS push notifications, fix missed implementation on android * Fix some issues on the push notifications, changed to Debug Console.WriteLine, and added update on entitlements on the build.yml
This commit is contained in:
committed by
GitHub
parent
42403210a0
commit
2791d4b8ec
@@ -1,11 +1,14 @@
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.App.Abstractions;
|
||||
using Foundation;
|
||||
using UIKit;
|
||||
using UserNotifications;
|
||||
|
||||
namespace Bit.iOS.Services
|
||||
{
|
||||
public class iOSPushNotificationService : IPushNotificationService
|
||||
public class iOSPushNotificationService : NSObject, IPushNotificationService, IUNUserNotificationCenterDelegate
|
||||
{
|
||||
private const string TokenSetting = "token";
|
||||
|
||||
@@ -14,13 +17,31 @@ namespace Bit.iOS.Services
|
||||
return Task.FromResult(NSUserDefaults.StandardUserDefaults.StringForKey(TokenSetting));
|
||||
}
|
||||
|
||||
public Task RegisterAsync()
|
||||
public bool IsRegisteredForPush => UIApplication.SharedApplication.IsRegisteredForRemoteNotifications;
|
||||
|
||||
public async Task RegisterAsync()
|
||||
{
|
||||
var userNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge |
|
||||
UIUserNotificationType.Sound;
|
||||
var settings = UIUserNotificationSettings.GetSettingsForTypes(userNotificationTypes, null);
|
||||
UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
|
||||
return Task.FromResult(0);
|
||||
var tcs = new TaskCompletionSource<bool>();
|
||||
|
||||
var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;
|
||||
UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) =>
|
||||
{
|
||||
if (error != null)
|
||||
{
|
||||
Debug.WriteLine($"Push Notifications {error}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.WriteLine($"Push Notifications {granted}");
|
||||
}
|
||||
|
||||
tcs.SetResult(granted);
|
||||
});
|
||||
|
||||
if (await tcs.Task)
|
||||
{
|
||||
UIApplication.SharedApplication.RegisterForRemoteNotifications();
|
||||
}
|
||||
}
|
||||
|
||||
public Task UnregisterAsync()
|
||||
|
||||
Reference in New Issue
Block a user