-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNotificationService.cs
61 lines (48 loc) · 2.03 KB
/
NotificationService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// ==========================================================================
// Notifo.io
// ==========================================================================
// Copyright (c) Sebastian Stehle
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System;
using Foundation;
using Notifo.SDK;
using Sample.iOS.Shared;
using UserNotifications;
namespace SampleNotificationServiceExtension
{
[Register("NotificationService")]
public class NotificationService : UNNotificationServiceExtension
{
public Action<UNNotificationContent> ContentHandler { get; set; }
public UNMutableNotificationContent BestAttemptContent { get; set; }
protected NotificationService(IntPtr handle)
: base(handle)
{
// Note: this constructor should not contain any initialization logic.
}
public override async void DidReceiveNotificationRequest(UNNotificationRequest request, Action<UNNotificationContent> contentHandler)
{
ContentHandler = contentHandler;
//Save the notification and create a mutable copy
BestAttemptContent = (UNMutableNotificationContent)request.Content.MutableCopy();
var notifo = NotifoIO.Current
.SetSharedName("group.io.notifo.xamarin.sample")
.SetNotificationHandler(new NotificationHandler());
notifo.OnLog += On_Log;
await NotifoIO.Current.DidReceiveNotificationRequestAsync(request, BestAttemptContent);
// Display the notification.
ContentHandler(BestAttemptContent);
}
private static void On_Log(object source, NotificationLogEventArgs e)
{
Console.WriteLine($"DEBUG: Log {e.Message} Message Args: {e.MessageArgs}", e.Message, e.MessageArgs);
}
public override void TimeWillExpire()
{
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
ContentHandler(BestAttemptContent);
}
}
}