123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- using System;
- using System.Threading.Tasks;
- using Foundation;
- using InABox.Mobile;
- using InABox.Mobile.iOS;
- using Plugin.LocalNotification.Platforms;
- using UIKit;
- using UserNotifications;
- using Xamarin.Forms;
- using PopupManager = InABox.Mobile.iOS.PopupManager;
- namespace PRS.Mobile.iOS
- {
- // The UIApplicationDelegate for the application. This class is responsible for launching the
- // User Interface of the application, as well as listening (and optionally responding) to
- // application events from iOS.
- [Register("AppDelegate")]
- public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
- {
- //
- // This method is invoked when the application has loaded and is ready to run. In this
- // method you should instantiate the window, load the UI into it and then make the window
- // visible.
- //
- // You have 17 seconds to return from this method, or iOS will terminate your application.
- //
- public override bool FinishedLaunching(UIApplication app, NSDictionary options)
- {
-
- AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
- TaskScheduler.UnobservedTaskException += TaskSchedulerOnUnobservedTaskException;
- DependencyService.Register<Version_iOS>();
- DependencyService.Register<IPopupManager, PopupManager>();
-
- global::Xamarin.Forms.Forms.Init();
-
- // https://learn.microsoft.com/en-au/xamarin/essentials/get-started?tabs=windows%2Cios
- //Xamarin.Essentials.Platform.Init( () => provide your own сurrent UIViewController provider);
-
- Syncfusion.SfRangeSlider.XForms.iOS.SfRangeSliderRenderer.Init();
- Syncfusion.SfImageEditor.XForms.iOS.SfImageEditorRenderer.Init();
- Syncfusion.SfMaps.XForms.iOS.SfMapsRenderer.Init();
- Syncfusion.XForms.iOS.MaskedEdit.SfMaskedEditRenderer.Init();
- Syncfusion.XForms.iOS.TreeView.SfTreeViewRenderer.Init();
- Syncfusion.SfSchedule.XForms.iOS.SfScheduleRenderer.Init();
- //new Syncfusion.SfSchedule.XForms.iOS.SfScheduleRenderer();
- Syncfusion.XForms.iOS.SignaturePad.SfSignaturePadRenderer.Init();
-
- // This needs to be moved to a JIT location (like the SfPopupLayout stuff)
- // 2024-04-05 Exception thrown at startup (CGDataProvider.Create)
- Syncfusion.XForms.iOS.TabView.SfTabViewRenderer.Init();
-
- Syncfusion.XForms.Pickers.iOS.SfTimePickerRenderer.Init();
-
- // This needs to be moved to a JIT location (like the SfPopupLayout stuff)
- // 2024-04-24 Exception thrown at startup (CGDataProvider.Create)
- Syncfusion.SfDataGrid.XForms.iOS.SfDataGridRenderer.Init();
- Syncfusion.SfPdfViewer.XForms.iOS.SfPdfDocumentViewRenderer.Init();
- new Syncfusion.SfBusyIndicator.XForms.iOS.SfBusyIndicatorRenderer();
- Syncfusion.SfPullToRefresh.XForms.iOS.SfPullToRefreshRenderer.Init();
-
-
- // https://github.com/Baseflow/XF-Material-Library
- XF.Material.iOS.Material.Init();
-
- // https://github.com/Redth/ZXing.Net.Mobile/tree/master
- ZXing.Net.Mobile.Forms.iOS.Platform.Init();
- Xamarin.IQKeyboardManager.SharedManager.Enable = true;
- Xamarin.IQKeyboardManager.SharedManager.EnableAutoToolbar = true;
- Xamarin.IQKeyboardManager.SharedManager.ShouldResignOnTouchOutside = true;
- Xamarin.IQKeyboardManager.SharedManager.ShouldToolbarUsesTextFieldTintColor = true;
- Xamarin.IQKeyboardManager.SharedManager.KeyboardDistanceFromTextField = 300f;
-
- if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
- {
- // Request notification permissions from the user
- UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Alert, (approved, err) =>
- {
- // Handle approval
- });
- }
- UNUserNotificationCenter.Current.Delegate = new UserNotificationCenterDelegate();
- if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
- {
- var notificationSettings = UIUserNotificationSettings.GetSettingsForTypes(
- UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, null
- );
- app.RegisterUserNotificationSettings(notificationSettings);
- }
- // check for a notification
- // check for a local notification
- if (options?.ContainsKey(UIApplication.LaunchOptionsLocalNotificationKey) == true)
- {
- var localNotification =
- options[UIApplication.LaunchOptionsLocalNotificationKey] as UILocalNotification;
- if (localNotification != null)
- {
- UIAlertController okayAlertController = UIAlertController.Create(localNotification.AlertAction,
- localNotification.AlertBody, UIAlertControllerStyle.Alert);
- okayAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
- Window.RootViewController.PresentViewController(okayAlertController, true, null);
- // reset our badge
- UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
- }
- }
- LoadApplication(new App());
- return base.FinishedLaunching(app, options);
- }
-
-
- public override void ReceivedLocalNotification(UIApplication application, UILocalNotification notification)
- {
- // show an alert
- UIAlertController okayAlertController = UIAlertController.Create(notification.AlertAction,
- notification.AlertBody, UIAlertControllerStyle.Alert);
- okayAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
- UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(okayAlertController,
- true, null);
- // reset our badge
- UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
- }
- public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
- {
-
- App.LaunchParameters = url.AbsoluteString.Remove(0, 15);
- LoadApplication(new App());
- return true;
- }
-
- #region Error handling
- private static void TaskSchedulerOnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs args)
- {
- LogUnhandledException("TaskScheduler", args.Exception?.GetType(), args.Exception);
- }
- private static void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs args)
- {
- LogUnhandledException("CurrentDomain", args.ExceptionObject?.GetType(), args.ExceptionObject);
- }
- private static void LogUnhandledException(String source, Type type, object exceptionobject)
- {
- if (exceptionobject is Exception exception)
- MobileLogging.Log(exception, source);
- else
- MobileLogging.Log($"{source}: {type?.Name ?? "NULL"} -> {exceptionobject}");
- }
- #endregion
- }
- }
|