wxr
2024-09-27 acc8caee31c4be90bd38d1af18136b0e84f6fe94
HDL-ON_iOS/AppDelegate.cs
@@ -3,10 +3,12 @@
using HDL_ON;
using Shared;
using UIKit;
using UserNotifications;
using HDL_ON.UI;
using HDL_ON.DAL.Server;
using Intents;
using System.Threading.Tasks;
using UserNotifications;
using Other;
using AVFoundation;
namespace SharedMethod
{
@@ -51,17 +53,22 @@
            set;
        }
        //public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        //{
        //    // Override point for customization after application launch.
        //    // If not required for your application you can safely delete this method
        //    return true;
        //}
        public static UINavigationController rootViewController;
        public static void CleanApplicationIconBadgeNumber()
        //public static void CleanApplicationIconBadgeNumber()
        //{
        //    UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
        //}
        [Export("application:shouldAllowExtensionPointIdentifier:")]
        public override bool ShouldAllowExtensionPointIdentifier(UIApplication application, NSString extensionPointIdentifier)
        {
            UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
            //if (extensionPointIdentifier == UIApplicationKeyboardExtensionPointIdentifier)
            //{
            //    return false;
            //}
            return true;
        }
        public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
@@ -89,14 +96,7 @@
            // Get previous device token
            var oldDeviceToken = NSUserDefaults.StandardUserDefaults.StringForKey("PushDeviceToken");
            //new Alert("", DeviceToken, "取消", "确定").Show();
            //NSDictionary test = new NSDictionary(new NSString("123"), new NSString("test"));
            //NSError error;
            //NSData dicD = NSJsonSerialization.Serialize(test, NSJsonWritingOptions.PrettyPrinted,out error); ;
            //NSString str = new NSString(dicD,NSStringEncoding.UTF8);
            //new Alert("", str, "取消", "确定").Show();
            // Has the token changed?
            if (string.IsNullOrEmpty(oldDeviceToken) || !oldDeviceToken.Equals(DeviceToken))
@@ -106,19 +106,12 @@
                // Save new device token 
                NSUserDefaults.StandardUserDefaults.SetString(DeviceToken, "PushDeviceToken");
                //UserInfo.Current.PushDeviceToken = DeviceToken;
                //UserInfo.Current.PhoneName = userPhoneName;
                //UserInfo.Current.SaveUserInfo();
                OnAppConfig.Instance.PushDeviceToken = DeviceToken;
                OnAppConfig.Instance.PhoneName = UIDevice.CurrentDevice.Name;
                OnAppConfig.Instance.SaveConfig();
            }
            if (OnAppConfig.Instance.PushDeviceToken != DeviceToken)
            {
                //string userPhoneName = UIDevice.CurrentDevice.Name;
                //UserInfo.Current.PushDeviceToken = DeviceToken;
                //UserInfo.Current.PhoneName = userPhoneName;
                //UserInfo.Current.SaveUserInfo();
                OnAppConfig.Instance.PushDeviceToken = DeviceToken;
                OnAppConfig.Instance.PhoneName = UIDevice.CurrentDevice.Name;
                OnAppConfig.Instance.SaveConfig();
@@ -127,34 +120,16 @@
        public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
        {
            Console.WriteLine("DidReceiveRemoteNotification:" + application.ApplicationState.ToString());
            Console.WriteLine("推送消息:"+userInfo);
            //var test = new NSDictionary();
            //test.SetNilValueForKey(new NSString("test"));
            //NSError error;
            //NSData dicD = NSJsonSerialization.Serialize(userInfo, NSJsonWritingOptions.PrettyPrinted, out error); ;
            //NSString str = new NSString(dicD, NSStringEncoding.UTF8);
            //new Alert("", str, "取消", "确定").Show();
            //读取推送信息
            UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
            if (userInfo == null)
            {
                return;
            }
            Console.WriteLine(userInfo);
            //HDLCommon.Current.ShowAlert("DidReceiveRemoteNotification:" + userInfo.ToString());
            if (application.ApplicationState == UIApplicationState.Active || application.ApplicationState == UIApplicationState.Background)
            {
                HandleNotificationMessageUserInfo(userInfo, false);
            }
            else
            //if (application.ApplicationState == UIApplicationState.Active || application.ApplicationState == UIApplicationState.Background)
            //{
            //    HandleNotificationMessageUserInfo(userInfo, false);
            //}
            //else
            {
                //Inactive
                HandleNotificationMessageUserInfo(userInfo, false);
@@ -177,10 +152,6 @@
            {
                Console.WriteLine("ReceivedRemoteNotification3");
            }
            //string extKey1 = "PushResType";
            //NSString extValue1 = userInfo.ValueForKey ((NSString)extKey1);
        }
        public override void OnResignActivation(UIApplication application)
@@ -193,7 +164,7 @@
            //    Shared.IOS.HDLFVSDK.Video.FVapplicationWillResignActive(application);
            //}
            Console.WriteLine("OnResignActivation");
            UserInfo.Current.unlockTime = DateTime.Now;
            //UserInfo.Current.unlockTime = DateTime.Now;
        }
        public override void DidEnterBackground(UIApplication application)
@@ -238,6 +209,7 @@
            //    Shared.IOS.HDLFVSDK.Video.FVapplicationDidBecomeActive(application);
            //}
            Console.WriteLine("OnActivated");
            base.OnActivated(application);
            //HDL_ON.DriverLayer.Control.Ins.SearchLoaclGateway();
@@ -257,16 +229,16 @@
        /// </summary>
        void SetCurrentLanguage()
        {
            if (string.IsNullOrEmpty(OnAppConfig.Instance.SetLanguage))
            {
            //if (string.IsNullOrEmpty(OnAppConfig.Instance.SetLanguage))
            //{
                if (NSLocale.PreferredLanguages[0].Contains("zh-"))
                {
                    Language.CurrentLanguage = "Chinese";
                }
                else if (NSLocale.PreferredLanguages[0].Contains("cs-"))
                {
                    Language.CurrentLanguage = "Czech";
                }
                //else if (NSLocale.PreferredLanguages[0].Contains("cs-"))
                //{
                //    Language.CurrentLanguage = "Czech";
                //}
                else if (NSLocale.PreferredLanguages[0].Contains("ru-"))
                {
                    Language.CurrentLanguage = "russian";
@@ -279,19 +251,38 @@
                {
                    Language.CurrentLanguage = "Spanish";
                }
                //else if(NSLocale.PreferredLanguages[0].Contains("uk-")){
                //    Language.CurrentLanguage = "Ukraine";
                //}
                else
                {
                    Language.CurrentLanguage = "English";
                }
            }
            else
            {
                Language.CurrentLanguage = OnAppConfig.Instance.SetLanguage;
            }
            //}
            //else
            //{
            //    Language.CurrentLanguage = OnAppConfig.Instance.SetLanguage;
            //}
        }
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            #region 异常捕获 2023-07-27 17:37:04
            AppDomain.CurrentDomain.UnhandledException += (sender, e) => {
                if(e.ExceptionObject is Exception exception)
                {
                    MainPage.Log("error", "未处理的异常:" + exception.Message + "StackTrace: " + exception.StackTrace);
                }
            };
            TaskScheduler.UnobservedTaskException += (sender, e) => {
                if (e.Exception is Exception exception)
                {
                    MainPage.Log("error", "未处理的异常:" + exception.Message + "StackTrace: " + exception.StackTrace);
                }
            };
            #endregion
            //设置全视通状态
            //string systemVersion = UIKit.UIDevice.CurrentDevice.SystemVersion;
@@ -300,10 +291,10 @@
            //{
            //    Shared.IOS.HDLFVSDK.Video.FVapplication(application, new NSDictionary());
            //}
            Console.WriteLine("111111111111");
            //Console.WriteLine("111111111111");
            SetCurrentLanguage();
            //Shared.Application.FontSize = 12;
            Bugly.Bugly.StartWithAppId("1dc40c170a");
            //Bugly.Bugly.StartWithAppId("1dc40c170a");
            //取消EditText默认密码输入方式
            //Shared.Application.IsEditTextContentTypePassword = false;
            //默认使用苹方字体
@@ -324,10 +315,22 @@
            // check for a notification
            DealWithPushMes(launchOptions);
            //if (UIApplication.SharedApplication.ApplicationIconBadgeNumber > 0)
            try
            {
                UMSdk.HDLUMSDK.InitUMSDKWithAppKey("61d56642e0f9bb492bbc3e72", "IOS");
            }
            catch(Exception ex)
            {
                Console.WriteLine("启动友盟SDK异常:"+ex.Message);
            }
            //// 注册进入前台的通知
            //NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.WillEnterForegroundNotification, (notification) =>
            //{
            //    //RemoteInfo.Current.ReadMsgList(true);
            //}
            //    // 停止播放铃声
            //    UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
            //    UNUserNotificationCenter.Current.RemoveAllDeliveredNotifications();
            //});
            Console.WriteLine("FinishedLaunching");
            return true;
@@ -400,11 +403,6 @@
                    Utlis.WriteLine("PushMes title : " + pushMes.Title);
                    Utlis.WriteLine("PushMes message : " + pushMes.Content);
                    Utlis.WriteLine("PushMes extras : " + pushMes.Extras);
                    if (!string.IsNullOrEmpty(pushMes.spk))//自研可视对讲需要记录时间反呼
                    {
                        UserInfo.Current.pushMessageInfo = pushMes;
                        UserInfo.Current.inCall = DateTime.Now;
                    }
                    if (bFinishedLaunching)
                    {
@@ -412,9 +410,8 @@
                        {
                            if (pushMes.Extras.Contains("OffLine"))
                            {
                                //haveToSignOut = true;
                                //强制下线
                                UserInfo.Current.LastTime = DateTime.MinValue;
                                UserInfo.Current.ValidToken = false;
                                UserInfo.Current.headImagePagePath = "LoginIcon/2.png";//重置用户头像
                                UserInfo.Current.SaveUserInfo();
                                HDLCommon.Current.ShowAlert(Language.StringByID(StringId.LoggedOnOtherDevices));
@@ -484,7 +481,7 @@
            //进入后台mqtt正在连接重置状态
            HDL_ON.DAL.Mqtt.MqttClient.RemoteMqttIsConnecting = false;
            HDL_ON.DriverLayer.UdpSocket._BusSocket.Stop();
        }
@@ -508,7 +505,7 @@
            HDL_ON.DAL.Mqtt.MqttClient.InitState();
            new AppUnlockPage().LoadPage();
            //new AppUnlockPage().LoadPage();
            UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
            HDL_ON.DriverLayer.Control.Ins.SearchLoaclGateway();
        }