Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
FirebasePushTransport.cs
1using System;
2using System.Threading;
3using Microsoft.Maui.Devices;
4using Plugin.Firebase.CloudMessaging;
5using Plugin.Firebase.CloudMessaging.EventArgs;
6using Waher.Events;
8
10{
15 {
16 private bool isInitialized;
17
21 public event EventHandlerAsync<TokenInformation>? TokenChanged;
22
27 public Task InitializeAsync(CancellationToken CancellationToken)
28 {
29 CancellationToken.ThrowIfCancellationRequested();
30
31 if (this.isInitialized)
32 return Task.CompletedTask;
33
34 this.isInitialized = true;
35
36 try
37 {
38 CrossFirebaseCloudMessaging.Current.TokenChanged += this.OnTokenChanged;
39 }
40 catch (Exception ex)
41 {
42 ServiceRef.LogService.LogException(ex);
43 }
44
45 return Task.CompletedTask;
46 }
47
48 private async void OnTokenChanged(object? Sender, FCMTokenChangedEventArgs EventArgs)
49 {
50 try
51 {
52 string? Token = EventArgs?.Token;
53 if (string.IsNullOrEmpty(Token))
54 return;
55
57 {
58 Token = Token,
59 Service = PushMessagingService.Firebase,
60 ClientType = ResolveClientType()
61 };
62
63 EventHandlerAsync<TokenInformation>? Handler = this.TokenChanged;
64 if (Handler is not null)
65 await Handler.Raise(this, TokenInformation);
66 }
67 catch (Exception ex)
68 {
69 ServiceRef.LogService.LogException(ex);
70 }
71 }
72
73 private static ClientType ResolveClientType()
74 {
75 if (DeviceInfo.Platform == DevicePlatform.Android)
76 return ClientType.Android;
77
78 if (DeviceInfo.Platform == DevicePlatform.iOS || DeviceInfo.Platform == DevicePlatform.MacCatalyst)
79 return ClientType.iOS;
80
81 return ClientType.Other;
82 }
83 }
84}
Firebase Cloud Messaging transport adapter.
Task InitializeAsync(CancellationToken CancellationToken)
Initializes the transport and wires platform callbacks.
EventHandlerAsync< TokenInformation >? TokenChanged
Raised when the transport receives a refreshed token.
Contains information about a push notification token.
Base class that references services in the app.
Definition: ServiceRef.cs:43
static ILogService LogService
Log service.
Definition: ServiceRef.cs:214
Abstraction for platform push transports (Firebase, APNS, WNS).
ClientType
Type of client requesting notification.
Definition: ClientType.cs:7
PushMessagingService
Push messaging service used.