AppDelegate.cs 6.5 KB

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