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 Foundation;
4using UIKit;
5
6
7namespace NeuroAccessMaui
8{
9 [Register("AppDelegate")]
10 public class AppDelegate : MauiUIApplicationDelegate
11 {
12
13 protected override MauiApp CreateMauiApp()
14 {
15 MauiApp app = MauiProgram.CreateMauiApp();
16#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
17
18 // TODO: This is a temporary workaround to fix the issue with custom RadioButton control templates not responding to taps on IOS
19 // https://github.com/dotnet/maui/issues/19478
20 RadioButtonTemplateWorkaround();
21
22 return app;
23 }
24
32 public override bool OpenUrl(UIApplication Application, NSUrl Url, NSDictionary Options)
33 {
34 if (string.IsNullOrEmpty(Url.AbsoluteString))
35 return false;
36
37 try
38 {
39 App.OpenUrlSync(Url.AbsoluteString);
40 }
41 catch (Exception ex)
42 {
43 ServiceRef.LogService.LogException(ex);
44 return false;
45 }
46 return true;
47 }
48
49
50 // At the time of writing 8/4/2024
51 // 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
52 // https://github.com/LuckyDucko/Mopups/issues/95
53 // https://github.com/dotnet/maui/issues/20408
54 // Might not be needed in future versions of MAUI/Mopups
55 // By ensuring we have a KeyWindow when the app is activated or resigns solves this issue.
56 public override void OnActivated(UIApplication application)
57 {
58 EnsureKeyWindow();
59 base.OnActivated(application);
60 }
61
62 public override void OnResignActivation(UIApplication application)
63 {
64 EnsureKeyWindow();
65 base.OnResignActivation(application);
66 }
67
68 private static void EnsureKeyWindow()
69 {
70 if (GetKeyWindow() is null)
71 return;
72
73 UIWindow? window = null;
74 if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
75 {
76 window = UIApplication.SharedApplication.ConnectedScenes
77 .OfType<UIWindowScene>()
78 .SelectMany(s => s.Windows)
79 .FirstOrDefault();
80 }
81 else
82 window = UIApplication.SharedApplication.Windows.FirstOrDefault();
83
84 if (window is null)
85 return;
86 if (!window!.IsKeyWindow)
87 window!.MakeKeyWindow();
88
89 }
90
95 internal static UIWindow? GetKeyWindow()
96 {
97 if (UIDevice.CurrentDevice.CheckSystemVersion(15, 0))
98 {
99 return UIApplication.SharedApplication.ConnectedScenes
100 .OfType<UIWindowScene>()
101 .SelectMany(s => s.Windows)
102 .FirstOrDefault(w => w.IsKeyWindow);
103 }
104 else if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
105 return UIApplication.SharedApplication.Windows.FirstOrDefault(w => w.IsKeyWindow);
106 else
107 return UIApplication.SharedApplication.KeyWindow;
108 }
109
110 private static void RadioButtonTemplateWorkaround()
111 {
112 Microsoft.Maui.Handlers.RadioButtonHandler.Mapper.AppendToMapping("TemplateWorkaround", (h, v) =>
113 {
114 if (h.PlatformView.CrossPlatformLayout is RadioButton radioButton)
115 {
116 radioButton.IsEnabled = false;
117 radioButton.ControlTemplate = RadioButton.DefaultTemplate;
118 radioButton.IsEnabled = true;
119 radioButton.ControlTemplate = AppStyles.RadioButtonTemplate;
120 }
121 });
122 }
123
124 /*
125 Not needed anymore as we have a new way to handle keyboard events in PlatformSpecific.cs, keeping this until new implementation has been tested
126 private void RegisterKeyBoardObserver()
127 {
128 this.onKeyboardShowObserver ??= UIKeyboard.Notifications.ObserveWillShow((object? Sender, UIKeyboardEventArgs Args) =>
129 {
130 NSDictionary? UserInfo = Args.Notification.UserInfo;
131
132 if (UserInfo is null)
133 {
134 return;
135 }
136
137 NSValue Result = (NSValue)UserInfo.ObjectForKey(new NSString(UIKeyboard.FrameEndUserInfoKey));
138 CGSize keyboardSize = Result.RectangleFValue.Size;
139
140 WeakReferenceMessenger.Default.Send(new KeyboardSizeMessage((float)keyboardSize.Height));
141 });
142
143 this.onKeyboardHideObserver ??= UIKeyboard.Notifications.ObserveWillHide((object? Sender, UIKeyboardEventArgs Args) =>
144 {
145 WeakReferenceMessenger.Default.Send(new KeyboardSizeMessage(0));
146 });
147 }
148 */
149 }
150}
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:32
The Application class, representing an instance of the Neuro-Access app.
Definition: App.xaml.cs:69
static void OpenUrlSync(string Url)
Opens an URL in the application.
Definition: App.xaml.cs:906
Base class that references services in the app.
Definition: ServiceRef.cs:31
static ILogService LogService
Log service.
Definition: ServiceRef.cs:91