using Syncfusion.SfPdfViewer.XForms.iOS; using Syncfusion.SfRangeSlider.XForms.iOS; using Syncfusion.XForms.iOS.MaskedEdit; using Syncfusion.XForms.iOS.TextInputLayout; using Syncfusion.SfRotator.XForms.iOS; using Syncfusion.SfPullToRefresh.XForms.iOS; using Syncfusion.XForms.iOS.TreeView; using Syncfusion.XForms.iOS.Buttons; using Syncfusion.ListView.XForms.iOS; using Foundation; using UIKit; using Matcha.BackgroundService.iOS; using Syncfusion.XForms.iOS.Accordion; using Syncfusion.XForms.iOS.TabView; using EmployeeApp.Model; using System; using Microsoft.AppCenter.Crashes; using Microsoft.AppCenter.Analytics; using System.Reflection; using Firebase.CloudMessaging; using UserNotifications; using ObjCRuntime; using Microsoft.AppCenter; namespace EmployeeApp.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, IUNUserNotificationCenterDelegate, IMessagingDelegate { /// NOTE: Dont delete this method otherwise app will not work [Export("messaging:didRefreshRegistrationToken:")] public void DidRefreshRegistrationToken(Messaging messaging, string fcmToken) { } [Export("messaging:didReceiveRegistrationToken:")] public void DidReceiveRegistrationToken(Messaging messaging, string fcmToken) { try { App.DeviceToken = messaging.FcmToken; } catch (Exception ex) { Crashes.TrackError(ex); Analytics.TrackEvent(string.Format("SessionID : {0}, Pagename : {1}, Methodname : {2}, Error : {3}", App.SessionID, MethodBase.GetCurrentMethod().ReflectedType.FullName, MethodBase.GetCurrentMethod().Name, ex.Message)); } } // // 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) { try { //AppCenter.Start(CommonFields.iOSKey, typeof(Analytics), typeof(Crashes)); //Analytics.TrackEvent("iOSPN:S try AppDelegate FinishedLaunching NT : " + DateTime.Now); global::Xamarin.Forms.Forms.Init(); BackgroundAggregator.Init(this); SfPdfDocumentViewRenderer.Init(); SfRangeSliderRenderer.Init(); SfMaskedEditRenderer.Init(); SfButtonRenderer.Init(); SfTextInputLayoutRenderer.Init(); SfSwitchRenderer.Init(); SfRotatorRenderer.Init(); SfPullToRefreshRenderer.Init(); SfTreeViewRenderer.Init(); SfCheckBoxRenderer.Init(); SfListViewRenderer.Init(); SfAccordionRenderer.Init(); SfTabViewRenderer.Init(); ZXing.Net.Mobile.Forms.iOS.Platform.Init(); new Syncfusion.XForms.iOS.ComboBox.SfComboBoxRenderer(); FFImageLoading.Forms.Platform.CachedImageRenderer.Init(); //For remote notification Firebase.Core.App.Configure(); LoadApplication(application: new App()); /** For remote notification **/ //Register your app for remote notifications. if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0)) { // iOS 10 or later var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound; UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) => { Console.WriteLine(granted); }); // For iOS 10 display notification (sent via APNS) UNUserNotificationCenter.Current.Delegate = this; // For iOS 10 data message (sent via FCM) Messaging.SharedInstance.Delegate = this; } else { // iOS 9 or before var allNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound; var settings = UIUserNotificationSettings.GetSettingsForTypes(allNotificationTypes, null); UIApplication.SharedApplication.RegisterUserNotificationSettings(settings); } UIApplication.SharedApplication.RegisterForRemoteNotifications(); /** ./For remote notification **/ UINavigationBar.Appearance.TintColor = UIColor.Black; UIApplication.SharedApplication.IdleTimerDisabled = true; //Analytics.TrackEvent("iOSPN:E try AppDelegate FinishedLaunching NT : " + DateTime.Now); } catch (Exception ex) { //Analytics.TrackEvent("iOSPN:Catch AppDelegate FinishedLaunching NT : " + DateTime.Now); Crashes.TrackError(ex); Analytics.TrackEvent(string.Format("SessionID : {0}, Pagename : {1}, Methodname : {2}, Error : {3}", App.SessionID, MethodBase.GetCurrentMethod().ReflectedType.FullName, MethodBase.GetCurrentMethod().Name, ex.Message)); } //Analytics.TrackEvent("iOSPN:return base.FinishedLaunching AppDelegate FinishedLaunching NT : " + DateTime.Now); return base.FinishedLaunching(app, options); } public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action completionHandler) { try { //Analytics.TrackEvent("iOSPN:S try AppDelegate DidReceiveRemoteNotification NT : " + DateTime.Now); if (userInfo != null) { //Analytics.TrackEvent("iOSPN:S try (userInfo != null) DidReceiveRemoteNotification NT : " + DateTime.Now); if (UIApplication.SharedApplication != null) { //Analytics.TrackEvent("iOSPN:S try (SharedApplication != null) DidReceiveRemoteNotification NT : " + DateTime.Now); UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0; var notificationType = userInfo.ValueForKey(new NSString(CommonFields.NotificationType)).ToString(); //Analytics.TrackEvent("iOSPN:S try (notificationType = "+ notificationType +") DidReceiveRemoteNotification NT : " + DateTime.Now); if (UIApplication.SharedApplication.ApplicationState.Equals(UIApplicationState.Active)) { //App is in foreground. Act on it. //Analytics.TrackEvent("iOSPN:S try (App is in forground) DidReceiveRemoteNotification NT : " + DateTime.Now); } else { if (!string.IsNullOrEmpty(notificationType)) { //Analytics.TrackEvent("iOSPN:S try (!string.IsNullOrEmpty(notificationType)) DidReceiveRemoteNotification NT : " + DateTime.Now); if (notificationType == NotificationType.AppNews) { //Analytics.TrackEvent("iOSPN:S try (notificationType = AppNews) DidReceiveRemoteNotification NT : " + DateTime.Now); App.RedirectPageName = PageName.News; } else if (notificationType == NotificationType.AppNotification) { //Analytics.TrackEvent("iOSPN:S try (notificationType = AppNotification) DidReceiveRemoteNotification NT : " + DateTime.Now); App.RedirectPageName = PageName.Notifications; } else { //Analytics.TrackEvent("iOSPN:S try (notificationType != else News) DidReceiveRemoteNotification NT : " + DateTime.Now); App.RedirectPageName = PageName.News; } } else { //Analytics.TrackEvent("iOSPN:S try (notificationType null else News) DidReceiveRemoteNotification NT : " + DateTime.Now); App.RedirectPageName = PageName.News; } } LoadApplication(application: new App()); //Xamarin.Forms.Application.Current.MainPage = new Views.StartupPage(); } } //Analytics.TrackEvent("iOSPN:E try AppDelegate DidReceiveRemoteNotification NT : " + DateTime.Now); } catch (Exception ex) { Crashes.TrackError(ex); Analytics.TrackEvent(string.Format("SessionID : {0}, Pagename : {1}, Methodname : {2}, Error : {3}", App.SessionID, MethodBase.GetCurrentMethod().ReflectedType.FullName, MethodBase.GetCurrentMethod().Name, ex.Message)); } } } }