AppDelegate.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. 
  2. using System;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Threading.Tasks;
  6. using Foundation;
  7. using InABox.Mobile;
  8. using InABox.Mobile.iOS;
  9. using Plugin.LocalNotification.Platforms;
  10. using UIKit;
  11. using UserNotifications;
  12. using Xamarin.Forms;
  13. using Syncfusion.TreeView;
  14. using Syncfusion.XForms.iOS.TreeView;
  15. using Syncfusion.XForms.iOS.PopupLayout;
  16. using Syncfusion.XForms.Pickers.iOS;
  17. namespace comal.timesheets.iOS
  18. {
  19. // The UIApplicationDelegate for the application. This class is responsible for launching the
  20. // User Interface of the application, as well as listening (and optionally responding) to
  21. // application events from iOS.
  22. [Register("AppDelegate")]
  23. public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
  24. {
  25. //
  26. // This method is invoked when the application has loaded and is ready to run. In this
  27. // method you should instantiate the window, load the UI into it and then make the window
  28. // visible.
  29. //
  30. // You have 17 seconds to return from this method, or iOS will terminate your application.
  31. //
  32. public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary launchOptions)
  33. {
  34. AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
  35. TaskScheduler.UnobservedTaskException += TaskSchedulerOnUnobservedTaskException;
  36. DependencyService.Register<Version_iOS>();
  37. global::Xamarin.Forms.Forms.Init();
  38. Syncfusion.XForms.iOS.PopupLayout.SfPopupLayoutRenderer.Init();
  39. Syncfusion.SfPdfViewer.XForms.iOS.SfPdfDocumentViewRenderer.Init();
  40. Syncfusion.SfRangeSlider.XForms.iOS.SfRangeSliderRenderer.Init();
  41. Syncfusion.SfImageEditor.XForms.iOS.SfImageEditorRenderer.Init();
  42. Syncfusion.SfDataGrid.XForms.iOS.SfDataGridRenderer.Init();
  43. Syncfusion.XForms.iOS.RichTextEditor.SfRichTextEditorRenderer.Init();
  44. Syncfusion.SfMaps.XForms.iOS.SfMapsRenderer.Init();
  45. Syncfusion.XForms.iOS.MaskedEdit.SfMaskedEditRenderer.Init();
  46. SfTreeViewRenderer.Init();
  47. Syncfusion.SfSchedule.XForms.iOS.SfScheduleRenderer.Init();
  48. new Syncfusion.SfSchedule.XForms.iOS.SfScheduleRenderer();
  49. XF.Material.iOS.Material.Init();
  50. ZXing.Net.Mobile.Forms.iOS.Platform.Init();
  51. Xamarin.IQKeyboardManager.SharedManager.Enable = true;
  52. Syncfusion.XForms.iOS.SignaturePad.SfSignaturePadRenderer.Init();
  53. Syncfusion.XForms.iOS.TabView.SfTabViewRenderer.Init();
  54. SfTimePickerRenderer.Init();
  55. if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
  56. {
  57. // Request notification permissions from the user
  58. UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Alert, (approved, err) =>
  59. {
  60. // Handle approval
  61. });
  62. }
  63. UNUserNotificationCenter.Current.Delegate = new UserNotificationCenterDelegate();
  64. if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
  65. {
  66. var notificationSettings = UIUserNotificationSettings.GetSettingsForTypes(
  67. UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, null
  68. );
  69. uiApplication.RegisterUserNotificationSettings(notificationSettings);
  70. }
  71. // check for a notification
  72. if (launchOptions != null)
  73. {
  74. // check for a local notification
  75. if (launchOptions.ContainsKey(UIApplication.LaunchOptionsLocalNotificationKey))
  76. {
  77. var localNotification =
  78. launchOptions[UIApplication.LaunchOptionsLocalNotificationKey] as UILocalNotification;
  79. if (localNotification != null)
  80. {
  81. UIAlertController okayAlertController = UIAlertController.Create(localNotification.AlertAction,
  82. localNotification.AlertBody, UIAlertControllerStyle.Alert);
  83. okayAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
  84. Window.RootViewController.PresentViewController(okayAlertController, true, null);
  85. // reset our badge
  86. UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
  87. }
  88. }
  89. }
  90. LoadApplication(new App());
  91. return base.FinishedLaunching(uiApplication, launchOptions);
  92. }
  93. public override void ReceivedLocalNotification(UIApplication application, UILocalNotification notification)
  94. {
  95. // show an alert
  96. UIAlertController okayAlertController = UIAlertController.Create(notification.AlertAction,
  97. notification.AlertBody, UIAlertControllerStyle.Alert);
  98. okayAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
  99. UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(okayAlertController,
  100. true, null);
  101. // reset our badge
  102. UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
  103. }
  104. public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
  105. {
  106. App.LaunchParameters = url.AbsoluteString.Remove(0, 17);
  107. LoadApplication(new App());
  108. return true;
  109. }
  110. #region Error handling
  111. private static void TaskSchedulerOnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs args)
  112. {
  113. LogUnhandledException("TaskScheduler", args.Exception?.GetType(), args.Exception);
  114. }
  115. private static void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs args)
  116. {
  117. LogUnhandledException("CurrentDomain", args.ExceptionObject?.GetType(), args.ExceptionObject);
  118. }
  119. private static void LogUnhandledException(String source, Type type, object exceptionobject)
  120. {
  121. if (exceptionobject is Exception exception)
  122. MobileLogging.Log(exception, source);
  123. else
  124. MobileLogging.Log($"{source}: {type?.Name ?? "NULL"} -> {exceptionobject}");
  125. }
  126. #endregion
  127. }
  128. }