public override void WillEnterForeground(UIApplication application)
        {
            // Called as part of the transiton from background to active state.
            // Here you can undo many of the changes made on entering the background.
            var ion = AppState.context as IosION;

            if (ion.settings.report.dataLoggingInterval.Seconds == 1)
            {
                if (intervalWarning == true)
                {
                    //UIAlertView loggingWarning = new UIAlertView(Util.Strings.Report.LOGGINGINTERVAL, Util.Strings.Report.LOWINTERVAL, null, Util.Strings.CLOSE, Util.Strings.RETURNSETTINGS);
                    UIAlertController loggingWarning = UIAlertController.Create(Util.Strings.Report.LOGGINGINTERVAL, Util.Strings.Report.LOWINTERVAL, UIAlertControllerStyle.Alert);

                    loggingWarning.AddAction(UIAlertAction.Create(Util.Strings.SETTINGS, UIAlertActionStyle.Default, (action) => {
                        UIApplication.SharedApplication.OpenUrl(new NSUrl(UIApplication.OpenSettingsUrlString));
                    }));

                    loggingWarning.AddAction(UIAlertAction.Create(Util.Strings.CLOSE, UIAlertActionStyle.Default, (action) => {}));

                    loggingWarning.Show();
                }
            }

            if (ion.settings.leaveScreenOn)
            {
                UIApplication.SharedApplication.IdleTimerDisabled = true;
            }
            if (ion.settings._location.allowsGps)
            {
                Console.WriteLine("Came back and using geolocation");
                ion.locationManager.StartAutomaticLocationPolling();
            }
            else
            {
                Console.WriteLine("Came back and not using geolocation");
                ion.locationManager.StopAutomaticLocationPolling();
            }
            var preWalkthrough = NSUserDefaults.StandardUserDefaults.StringForKey("walkthrough_complete");

            if (string.IsNullOrEmpty(preWalkthrough))
            {
                string lastDate = NSUserDefaults.StandardUserDefaults.StringForKey("rssCheck");

                if (!string.IsNullOrEmpty(lastDate) && DateTime.Parse(lastDate).ToLocalTime().AddHours(24) <= DateTime.Now.ToLocalTime())
                {
                    var feedPull = new ViewController.RssFeed.RssFeedCheck();
                    feedPull.BeginReadXMLStreamSingle();
                }
            }
        }
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // Initialize the application state.
            // Set Navigation Bar preferences
            UILabel.Appearance.Font = UIFont.FromName("DroidSans", 20f);


            AppState.context = ion = new LocalIosION(new IONPortalService());
            try {
                ion.InitAsync().Wait();
            } catch (Exception e) {
                Log.E(this, "Failed to initialize ion.", e);
                Environment.Exit(1);
            }
            // create a new window instance based on the screen size
            Window = new UIWindow(UIScreen.MainScreen.Bounds);

            Window.RootViewController = STORYBOARD.InstantiateInitialViewController();

            // make the window visible
            Window.MakeKeyAndVisible();
            NSUserDefaults.StandardUserDefaults.SetString("", "viewedUser");

            var preWalkthrough = NSUserDefaults.StandardUserDefaults.StringForKey("walkthrough_complete");

            if (string.IsNullOrEmpty(preWalkthrough))
            {
                var ionvc          = (IONPrimaryScreenController)Window.RootViewController;
                var appdnavigation = ionvc.navigation;

                var ret = (WalkthroughScreenshotViewController)STORYBOARD.InstantiateViewController(BaseIONViewController.VC_WALKTHROUGH_MENU);
                ret.initial = true;

                var nvc = ((UINavigationController)appdnavigation.CurrentViewController).VisibleViewController;
                nvc.NavigationController.PushViewController(ret, true);
                NSUserDefaults.StandardUserDefaults.SetString("1", "walkthrough_complete");
            }
            else
            {
                Console.WriteLine("Checking app version for popup");
                //*********CHECK APP VERSION!!!!!
                //var record = KeychainAccess.ValueForKey("lastUsedVersion");
                var record = NSUserDefaults.StandardUserDefaults.StringForKey("lastUsedVersion");

                if (!string.IsNullOrEmpty(record))
                {
                    var currentVersion = NSBundle.MainBundle.InfoDictionary["CFBundleVersion"].ToString();
                    var latestVersion  = record;

                    if (!currentVersion.Equals(latestVersion))
                    {
                        var window = UIApplication.SharedApplication.KeyWindow;
                        var vc     = window.RootViewController;
                        while (vc.PresentedViewController != null)
                        {
                            vc = vc.PresentedViewController;
                        }
                        var updateView = new WhatsNewView(vc.View, vc);
                        vc.View.AddSubview(updateView.infoView);
                        NSUserDefaults.StandardUserDefaults.SetString(NSBundle.MainBundle.InfoDictionary["CFBundleVersion"].ToString(), "lastUsedVersion");
                    }
                    ////////USE THIS TO RESET VERSION NUMBER FOR TESTING WHAT'S NEW POPUP/////////
                    //else{
                    //	NSUserDefaults.StandardUserDefaults.SetString("1.0","lastUsedVersion");
                    //}
                }
                else
                {
                    var window = UIApplication.SharedApplication.KeyWindow;
                    var vc     = window.RootViewController;
                    while (vc.PresentedViewController != null)
                    {
                        vc = vc.PresentedViewController;
                    }
                    var updateView = new WhatsNewView(vc.View, vc);
                    vc.View.AddSubview(updateView.infoView);
                    //KeychainAccess.SetValueForKey(NSBundle.MainBundle.InfoDictionary["CFBundleVersion"].ToString(),"lastUsedVersion");
                    NSUserDefaults.StandardUserDefaults.SetString(NSBundle.MainBundle.InfoDictionary["CFBundleVersion"].ToString(), "lastUsedVersion");
                }
                //**********CHECK RSS FEED UPDATES!!!!!!!!

                var feedPull = new ViewController.RssFeed.RssFeedCheck();
                feedPull.BeginReadXMLStreamSingle();

                //************************************************************************
            }

            /*********************CHECK REPORTING DEFAULTS***************************/
            var defaultSpreadsheet = NSUserDefaults.StandardUserDefaults.StringForKey("user_spreadsheet_default");

            if (string.IsNullOrEmpty(defaultSpreadsheet))
            {
                NSUserDefaults.StandardUserDefaults.SetString("0", "user_spreadsheet_default");
                Console.WriteLine("Set blank user pdf setting to " + NSUserDefaults.StandardUserDefaults.StringForKey("user_spreadsheet_default"));
            }
            var defaultData = NSUserDefaults.StandardUserDefaults.StringForKey("user_data_default");

            if (string.IsNullOrEmpty(defaultData))
            {
                NSUserDefaults.StandardUserDefaults.SetString("0", "user_data_default");
                Console.WriteLine("Set blank user raw data setting to " + NSUserDefaults.StandardUserDefaults.StringForKey("user_data_default"));
            }
            var defaultPDF = NSUserDefaults.StandardUserDefaults.StringForKey("user_pdf_default");

            if (string.IsNullOrEmpty(defaultPDF))
            {
                NSUserDefaults.StandardUserDefaults.SetString("0", "user_pdf_default");
                Console.WriteLine("Set blank user pdf setting to " + NSUserDefaults.StandardUserDefaults.StringForKey("user_spreadsheet_default"));
            }
            //************************************************************************
            /*********************CHECK TRENDING DEFAULTS***************************/
            var defaultTrending = NSUserDefaults.StandardUserDefaults.StringForKey("settings_default_trending_interval");

            if (string.IsNullOrEmpty(defaultTrending))
            {
                NSUserDefaults.StandardUserDefaults.SetInt(100, "settings_default_trending_interval");
                Console.WriteLine("No trending default was set so it is now");
            }
            //************************************************************************

            return(true);
        }