diff --git a/src/iOS/AppDelegate.cs b/src/iOS/AppDelegate.cs index 266ec429a..94126e2e0 100644 --- a/src/iOS/AppDelegate.cs +++ b/src/iOS/AppDelegate.cs @@ -21,6 +21,7 @@ using Google.Analytics; using FFImageLoading.Forms.Touch; using SimpleInjector; using XLabs.Ioc.SimpleInjectorContainer; +using UserNotifications; namespace Bit.iOS { @@ -36,6 +37,8 @@ namespace Bit.iOS { global::Xamarin.Forms.Forms.Init(); + UNUserNotificationCenter.Current.Delegate = new UserNotificationCenterDelegate(); + if(!Resolver.IsSet) { SetIoc(); diff --git a/src/iOS/Services/iOSPushNotificationService.cs b/src/iOS/Services/iOSPushNotificationService.cs index 81040ecaf..882d6f23a 100644 --- a/src/iOS/Services/iOSPushNotificationService.cs +++ b/src/iOS/Services/iOSPushNotificationService.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Threading; using UIKit; +using UserNotifications; using Xamarin.Forms; namespace Bit.iOS.Services @@ -17,7 +18,7 @@ namespace Bit.iOS.Services public void Register() { - var userNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | + var userNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound; var settings = UIUserNotificationSettings.GetSettingsForTypes(userNotificationTypes, null); UIApplication.SharedApplication.RegisterUserNotificationSettings(settings); @@ -104,10 +105,24 @@ namespace Bit.iOS.Services void OnUnregisteredSuccess(); } + public class UserNotificationCenterDelegate : UNUserNotificationCenterDelegate + { + public override void WillPresentNotification(UNUserNotificationCenter center, + UNNotification notification, Action completionHandler) + { + Debug.WriteLine("WillPresentNotification: {0}", notification); + + if(CrossPushNotification.Current is IPushNotificationHandler) + { + //((IPushNotificationHandler)CrossPushNotification.Current).OnMessageReceived(); + } + } + } + internal class CrossPushNotification { private static Lazy Implementation = new Lazy( - () => new iOSPushNotificationService(), + () => new iOSPushNotificationService(), LazyThreadSafetyMode.PublicationOnly); public static bool IsInitialized => PushNotificationListener != null; public static IPushNotificationListener PushNotificationListener { get; private set; }