JLChen
2021-01-11 5a5a2b696866f947b6025d26c3302e8ffef46435
Crabtree/ON.Ios/AppDelegate.cs
@@ -6,6 +6,8 @@
using Microsoft.AppCenter.Analytics;
using Microsoft.AppCenter.Crashes;
using Shared;
using Shared.SimpleControl;
using SmartHome;
using UIKit;
using UserNotifications;
@@ -75,9 +77,9 @@
            AppCenter.Start ("44cbdfbf-d33e-4e92-a795-1c4452e54d3e", typeof (Analytics), typeof (Crashes));
            Utlis.WriteLine ("FinishedLaunching");
            //Shared.Application.IsGpsEnable = false;
            //Shared.Application.IsUsePingFang = true;
            base.FinishedLaunching (application, launchOptions);
            SharedMethod.SharedMethod.sharedApp = application;
@@ -191,13 +193,15 @@
        public override void OnResignActivation (UIApplication application)
        {
            Utlis.WriteLine ("OnResignActivation");
            Shared.BusSocket.Stop ();
            //Shared.BusSocket.Stop ();
            //BusSocketStop ();
        }
        public override void DidEnterBackground (UIApplication application)
        {
            SharedMethod.SharedMethod.IsBackground = true;
            Utlis.WriteLine ("DidEnterBackground");
            BusSocketStop ();
        }
        public override void WillEnterForeground (UIApplication application)
@@ -209,6 +213,7 @@
            UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
            // Called as part of the transiton from background to active state.
            // Here you can undo many of the changes made on entering the background.
            BusSocketStart ();
        }
        public override void WillTerminate (UIApplication application)
@@ -222,6 +227,64 @@
            Utlis.WriteLine ("OnActivated");
            base.OnActivated (application);
            //BusSocketStart ();
            ////有些系统版本这里启动比视图控制器快
            //if (!Shared.SimpleControl.MainPage.Showed) {
            //    System.Threading.Tasks.Task.Run (() => {
            //        while (true) {
            //            System.Threading.Thread.Sleep (10);
            //            if (Shared.SimpleControl.MainPage.Showed) {
            //                break;
            //            }
            //        }
            //        Shared.Application.RunOnMainThread (() => {
            //            Shared.BusSocket.Start (6000);
            //            Shared.SimpleControl.EquipmentPublicClass.CheckLinkRemote ((int)Reachability.InternetConnectionStatus (),false);
            //            //RemoteInfo.Current.ReadMsgList (NSUserDefaults.StandardUserDefaults.StringForKey ("PushDeviceToken"), true);
            //            if (SmartHome.WiFiSet.refreshView != null) {
            //                SmartHome.WiFiSet.refreshView ();
            //            }
            //        });
            //    });
            //    return;
            //}
            //Shared.BusSocket.Start (6000);
            //Shared.SimpleControl.EquipmentPublicClass.CheckLinkRemote ((int)Reachability.InternetConnectionStatus (), false);
            //if (SmartHome.WiFiSet.refreshView != null) {
            //    SmartHome.WiFiSet.refreshView ();
            //}
            //com.freeview.global.Video.FVapplicationDidBecomeActive (application);
        }
        DateTime closeTime = DateTime.MinValue;
        /// <summary>
        /// BusSocketStop
        /// </summary>
        void BusSocketStop ()
        {
            //进入后台mqtt正在连接重置状态
            MqttCommon.remoteMqttIsConnecting = false;
            Shared.BusSocket.Stop ();
            closeTime = DateTime.Now;
        }
        /// <summary>
        /// BusSocketStart
        /// </summary>
        void BusSocketStart ()
        {
            if (closeTime == DateTime.MinValue) {
                closeTime = DateTime.Now;
            } else if (closeTime.AddSeconds (10) < DateTime.Now) {
                if (CommonPage.IsRemote) {
                    MqttCommon.DisConnectRemote ("closeTime", false);
                }
            }
            var netStatus = (int)Reachability.InternetConnectionStatus ();
            //有些系统版本这里启动比视图控制器快
            if (!Shared.SimpleControl.MainPage.Showed) {
                System.Threading.Tasks.Task.Run (() => {
@@ -233,23 +296,24 @@
                    }
                    Shared.Application.RunOnMainThread (() => {
                        Shared.BusSocket.Start (6000);
                        Shared.SimpleControl.EquipmentPublicClass.CheckLinkRemote ((int)Reachability.InternetConnectionStatus (),false);
                        //RemoteInfo.Current.ReadMsgList (NSUserDefaults.StandardUserDefaults.StringForKey ("PushDeviceToken"), true);
                        Shared.SimpleControl.EquipmentPublicClass.CheckLinkRemote (netStatus, false);
                        //RemoteInfo.Current.ReadMsgList (true);
                        if (SmartHome.WiFiSet.refreshView != null) {
                            SmartHome.WiFiSet.refreshView ();
                        }
                    });
                });
                return;
            } else {
                Shared.BusSocket.Start (6000);
                Shared.SimpleControl.EquipmentPublicClass.CheckLinkRemote (netStatus, false);
                //RemoteInfo.Current.ReadMsgList (true);
            }
            Shared.BusSocket.Start (6000);
            Shared.SimpleControl.EquipmentPublicClass.CheckLinkRemote ((int)Reachability.InternetConnectionStatus (), false);
            if (SmartHome.WiFiSet.refreshView != null) {
                SmartHome.WiFiSet.refreshView ();
            }
            //com.freeview.global.Video.FVapplicationDidBecomeActive (application);
            if (netStatus == 0)
                return;
        }
    }
}