Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
AppDelegate.cs
1using Firebase.CloudMessaging;
2using Foundation;
7using Plugin.Firebase.Core.Platforms.iOS;
8using UIKit;
9using UserNotifications;
10
11
12namespace NeuroAccessMaui
13{
14 [Register("AppDelegate")]
15 public class AppDelegate : MauiUIApplicationDelegate
16 {
17
18 protected override MauiApp CreateMauiApp()
19 {
20 MauiApp app = MauiProgram.CreateMauiApp();
21#warning Remove this line when the issue with the RadioButton control template is fixed in a future version of MAUI https://github.com/dotnet/maui/issues/19478
22
23 // TODO: This is a temporary workaround to fix the issue with custom RadioButton control templates not responding to taps on IOS
24 // https://github.com/dotnet/maui/issues/19478
25 RadioButtonTemplateWorkaround();
26
27 return app;
28 }
29
30 [Export("application:didReceiveRemoteNotification:fetchCompletionHandler:")]
31 public static void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
32 {
33 Console.WriteLine("Silent data notification received: " + userInfo);
34
35 try
36 {
37 NotificationDelegate.ProcessSilentNotification(userInfo);
38 }
39 catch (Exception Ex)
40 {
41 ServiceRef.LogService.LogException(Ex);
42 }
43
44 completionHandler(UIBackgroundFetchResult.NewData);
45 }
46
47 [Export("application:didRegisterForRemoteNotificationsWithDeviceToken:")]
48 public static void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
49 {
50 Messaging.SharedInstance.ApnsToken = deviceToken;
51 }
52
60 public override bool OpenUrl(UIApplication Application, NSUrl Url, NSDictionary Options)
61 {
62 if (string.IsNullOrEmpty(Url.AbsoluteString))
63 return false;
64
65 try
66 {
67 // Create a deep link intent.
68 AppIntent AppIntent = new()
69 {
71 Data = Url.AbsoluteString
72 };
73
74 // Retrieve the shared intent service and queue the intent.
77 IntentService.ProcessIntentAsync(AppIntent).ConfigureAwait(false);
78 else
80 }
81 catch (Exception Ex)
82 {
83 ServiceRef.LogService.LogException(Ex);
84 return false;
85 }
86 return true;
87 }
88
89
90 // At the time of writing 8/4/2024
91 // There is a bug with the MAUI/Mopups library that causes the app to crash because some of the apps lifecycle events are not forwarded properly
92 // https://github.com/LuckyDucko/Mopups/issues/95
93 // https://github.com/dotnet/maui/issues/20408
94 // Might not be needed in future versions of MAUI/Mopups
95 // By ensuring we have a KeyWindow when the app is activated or resigns solves this issue.
96 public override void OnActivated(UIApplication application)
97 {
98 EnsureKeyWindow();
99 base.OnActivated(application);
100 }
101
102 public override void OnResignActivation(UIApplication application)
103 {
104 EnsureKeyWindow();
105 base.OnResignActivation(application);
106 }
107
108 private static void EnsureKeyWindow()
109 {
110 if (GetKeyWindow() is null)
111 return;
112
113 UIWindow? Window = null;
114 if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
115 {
116 Window = UIApplication.SharedApplication.ConnectedScenes
117 .OfType<UIWindowScene>()
118 .SelectMany(s => s.Windows)
119 .FirstOrDefault();
120 }
121 else
122 Window = UIApplication.SharedApplication.Windows.FirstOrDefault();
123
124 if (Window is null)
125 return;
126 if (!Window!.IsKeyWindow)
127 Window!.MakeKeyWindow();
128
129 }
130
135 internal static UIWindow? GetKeyWindow()
136 {
137 if (UIDevice.CurrentDevice.CheckSystemVersion(15, 0))
138 {
139 return UIApplication.SharedApplication.ConnectedScenes
140 .OfType<UIWindowScene>()
141 .SelectMany(s => s.Windows)
142 .FirstOrDefault(w => w.IsKeyWindow);
143 }
144 else if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
145 return UIApplication.SharedApplication.Windows.FirstOrDefault(w => w.IsKeyWindow);
146 else
147 return UIApplication.SharedApplication.KeyWindow;
148 }
149
150 private static void RadioButtonTemplateWorkaround()
151 {
152 Microsoft.Maui.Handlers.RadioButtonHandler.Mapper.AppendToMapping("TemplateWorkaround", (h, v) =>
153 {
154 if (h.PlatformView.CrossPlatformLayout is RadioButton RadioButton)
155 {
156 RadioButton.IsEnabled = false;
157 RadioButton.ControlTemplate = RadioButton.DefaultTemplate;
158 RadioButton.IsEnabled = true;
159 RadioButton.ControlTemplate = AppStyles.RadioButtonTemplate;
160 }
161 });
162 }
163
164
165
166 /*
167 Not needed anymore as we have a new way to handle keyboard events in PlatformSpecific.cs, keeping this until new implementation has been tested
168 private void RegisterKeyBoardObserver()
169 {
170 this.onKeyboardShowObserver ??= UIKeyboard.Notifications.ObserveWillShow((object? Sender, UIKeyboardEventArgs Args) =>
171 {
172 NSDictionary? UserInfo = Args.Notification.UserInfo;
173
174 if (UserInfo is null)
175 {
176 return;
177 }
178
179 NSValue Result = (NSValue)UserInfo.ObjectForKey(new NSString(UIKeyboard.FrameEndUserInfoKey));
180 CGSize keyboardSize = Result.RectangleFValue.Size;
181
182 WeakReferenceMessenger.Default.Send(new KeyboardSizeMessage((float)keyboardSize.Height));
183 });
184
185 this.onKeyboardHideObserver ??= UIKeyboard.Notifications.ObserveWillHide((object? Sender, UIKeyboardEventArgs Args) =>
186 {
187 WeakReferenceMessenger.Default.Send(new KeyboardSizeMessage(0));
188 });
189 }
190 */
191 }
192}
override bool OpenUrl(UIApplication Application, NSUrl Url, NSDictionary Options)
Method is called when an URL with a registered schema is being opened.
Definition: AppDelegate.cs:60
Represents an instance of the Neuro-Access app.
Definition: App.xaml.cs:125
Contains intent action constants used for inter-component communication within the app.
Definition: Constants.cs:1060
const string OpenUrl
Action used to open a URL, typically triggered by deep linking.
Definition: Constants.cs:1064
A set of never changing property constants and helpful values.
Definition: Constants.cs:24
Represents an application intent containing an action, optional data, and an optional payload.
The IntentService class is responsible for handling and processing application intents in a cross‑pla...
void QueueIntent(AppIntent intent)
Queues an intent for later processing.
async Task ProcessIntentAsync(AppIntent intent)
Processes a single intent asynchronously.
Base class that references services in the app.
Definition: ServiceRef.cs:43
static ILogService LogService
Log service.
Definition: ServiceRef.cs:214
static ITagProfile TagProfile
TAG Profile service.
Definition: ServiceRef.cs:202
Defines the contract for a service that handles application intents.
RegistrationStep Step
This profile's current registration step.
Definition: ITagProfile.cs:172
RegistrationStep
The different steps of a TAG Profile registration journey.