1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-16 08:13:20 +00:00
Files
mobile/src/iOS/Services/iOSPushNotificationService.cs
2017-12-21 23:26:46 -05:00

39 lines
1.3 KiB
C#

using Bit.App.Abstractions;
using Foundation;
using UIKit;
using Xamarin.Forms;
namespace Bit.iOS.Services
{
public class iOSPushNotificationService : IPushNotificationService
{
private const string TokenSetting = "token";
private readonly IPushNotificationListener _pushNotificationListener;
public iOSPushNotificationService(
IPushNotificationListener pushNotificationListener)
{
_pushNotificationListener = pushNotificationListener;
}
public string Token => NSUserDefaults.StandardUserDefaults.StringForKey(TokenSetting);
public void Register()
{
var userNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge |
UIUserNotificationType.Sound;
var settings = UIUserNotificationSettings.GetSettingsForTypes(userNotificationTypes, null);
UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
}
public void Unregister()
{
UIApplication.SharedApplication.UnregisterForRemoteNotifications();
_pushNotificationListener.OnUnregistered(Device.iOS);
NSUserDefaults.StandardUserDefaults.SetString(string.Empty, TokenSetting);
NSUserDefaults.StandardUserDefaults.Synchronize();
}
}
}