Skip to content

Commit

Permalink
Add some logging, increase immediate notification delay for iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-moussa committed Oct 15, 2020
1 parent 334a94c commit e2226fe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/Plugin.LocalNotifications.Android/NotificationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public ILocalNotificationBuilder WithActionSet(string actionSetId, string parame

public void Show(DateTime notifyTime)
{
Console.WriteLine($"Will show notification (id: {_id}) with title '{_title}' at {notifyTime}");

var localNotification = BuildLocalNotification();
localNotification.NotifyTime = notifyTime;
localNotification.IconId = GetIconId(_iconId);
Expand All @@ -81,6 +83,8 @@ public void Show(DateTime notifyTime)

public void Show()
{
Console.WriteLine($"Will show notification (id: {_id}) with title '{_title}' immediately");

Notify(BuildLocalNotification());
}

Expand Down
4 changes: 3 additions & 1 deletion src/Plugin.LocalNotifications.iOS/NotificationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public ILocalNotificationBuilder WithActionSet(string id, string parameter)

public void Show(DateTime notifyAt)
{
Console.WriteLine($"Will show notification (id: {_id}) with title '{_title}' at {notifyAt}");

if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
{
var trigger = UNCalendarNotificationTrigger.CreateTrigger(GetNSDateComponentsFromDateTime(notifyAt), false);
Expand Down Expand Up @@ -79,7 +81,7 @@ public void Show(DateTime notifyAt)

public void Show()
{
Show(DateTime.Now.AddSeconds(1));
Show(DateTime.Now.AddSeconds(2));
}

private void ShowUserNotification(UNNotificationTrigger trigger)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Foundation;
using Plugin.LocalNotifications.Abstractions;
using Plugin.LocalNotifications.Models;
using UserNotifications;
Expand Down Expand Up @@ -28,8 +29,9 @@ public ILocalNotificationActionRegistrar NewActionRegistrar(string id)
var registrar = new ActionRegistrar(id);
_actionRegistrars.Add(registrar);
return registrar;
}
}

[Export("userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:")]
public override void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler)
{
var actionSetId = response.Notification.Request.Content.CategoryIdentifier;
Expand Down Expand Up @@ -58,8 +60,11 @@ public override void DidReceiveNotificationResponse(UNUserNotificationCenter cen
completionHandler();
}

[Export("userNotificationCenter:willPresentNotification:withCompletionHandler:")]
public override void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler)
{
Console.WriteLine($"Will present notification: {notification}");

completionHandler(UNNotificationPresentationOptions.Alert |
UNNotificationPresentationOptions.Sound |
UNNotificationPresentationOptions.Badge);
Expand Down

0 comments on commit e2226fe

Please sign in to comment.