1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-23 11:45:38 +01:00

UNUserNotificationCenterDelegate

This commit is contained in:
Kyle Spearrin 2017-10-10 09:13:09 -04:00
parent 6040c7768f
commit 04e42c4a75
2 changed files with 20 additions and 2 deletions

View File

@ -21,6 +21,7 @@ using Google.Analytics;
using FFImageLoading.Forms.Touch; using FFImageLoading.Forms.Touch;
using SimpleInjector; using SimpleInjector;
using XLabs.Ioc.SimpleInjectorContainer; using XLabs.Ioc.SimpleInjectorContainer;
using UserNotifications;
namespace Bit.iOS namespace Bit.iOS
{ {
@ -36,6 +37,8 @@ namespace Bit.iOS
{ {
global::Xamarin.Forms.Forms.Init(); global::Xamarin.Forms.Forms.Init();
UNUserNotificationCenter.Current.Delegate = new UserNotificationCenterDelegate();
if(!Resolver.IsSet) if(!Resolver.IsSet)
{ {
SetIoc(); SetIoc();

View File

@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Threading; using System.Threading;
using UIKit; using UIKit;
using UserNotifications;
using Xamarin.Forms; using Xamarin.Forms;
namespace Bit.iOS.Services namespace Bit.iOS.Services
@ -17,7 +18,7 @@ namespace Bit.iOS.Services
public void Register() public void Register()
{ {
var userNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | var userNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge |
UIUserNotificationType.Sound; UIUserNotificationType.Sound;
var settings = UIUserNotificationSettings.GetSettingsForTypes(userNotificationTypes, null); var settings = UIUserNotificationSettings.GetSettingsForTypes(userNotificationTypes, null);
UIApplication.SharedApplication.RegisterUserNotificationSettings(settings); UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
@ -104,10 +105,24 @@ namespace Bit.iOS.Services
void OnUnregisteredSuccess(); void OnUnregisteredSuccess();
} }
public class UserNotificationCenterDelegate : UNUserNotificationCenterDelegate
{
public override void WillPresentNotification(UNUserNotificationCenter center,
UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler)
{
Debug.WriteLine("WillPresentNotification: {0}", notification);
if(CrossPushNotification.Current is IPushNotificationHandler)
{
//((IPushNotificationHandler)CrossPushNotification.Current).OnMessageReceived();
}
}
}
internal class CrossPushNotification internal class CrossPushNotification
{ {
private static Lazy<IPushNotificationService> Implementation = new Lazy<IPushNotificationService>( private static Lazy<IPushNotificationService> Implementation = new Lazy<IPushNotificationService>(
() => new iOSPushNotificationService(), () => new iOSPushNotificationService(),
LazyThreadSafetyMode.PublicationOnly); LazyThreadSafetyMode.PublicationOnly);
public static bool IsInitialized => PushNotificationListener != null; public static bool IsInitialized => PushNotificationListener != null;
public static IPushNotificationListener PushNotificationListener { get; private set; } public static IPushNotificationListener PushNotificationListener { get; private set; }