From 17355977e81bb1f93862b5201424f60af9d093cf Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期六, 05 十二月 2020 16:21:44 +0800
Subject: [PATCH] 2020-12-05 1.增加苹果推送处理。2.暂时通过推送实现,增加挤下线功能。

---
 HDL-ON_iOS/AppDelegate.cs |  202 ++++++++++++++++++--------------------------------
 1 files changed, 73 insertions(+), 129 deletions(-)

diff --git a/HDL-ON_iOS/AppDelegate.cs b/HDL-ON_iOS/AppDelegate.cs
index 3728f8d..652593e 100644
--- a/HDL-ON_iOS/AppDelegate.cs
+++ b/HDL-ON_iOS/AppDelegate.cs
@@ -8,6 +8,7 @@
 using Microsoft.AppCenter.Analytics;
 using Microsoft.AppCenter.Crashes;
 using HDL_ON.UI;
+using HDL_ON.DAL.Server;
 
 namespace SharedMethod
 {
@@ -34,6 +35,7 @@
         //}
     }
 
+    
 }
 
 namespace HDL_ON_iOS
@@ -128,89 +130,13 @@
 
             if (application.ApplicationState == UIApplicationState.Active || application.ApplicationState == UIApplicationState.Background)
             {
-                NSString key_hiddenJson = new NSString("HiddenJson");
-                if (userInfo.ContainsKey(key_hiddenJson))
-                {
-                    var hiddenJson = userInfo["HiddenJson"].ToString();
-                    if (string.IsNullOrEmpty(hiddenJson))
-                    {
-                        return;
-                    }
 
-                    if (hiddenJson.Contains("cmtID"))
-                    {
-                        /////鐩墠鏍规嵁杩欎釜鍒ゆ柇鏄惁鏄彲瑙嗗璁叉暟鎹�
-                        //VideoMethod(hiddenJson);
-                    }
-                    else
-                    {
-
-                        NSDictionary hiddenJsonDic = userInfo["HiddenJson"] as NSDictionary;
-                        if (hiddenJsonDic == null)
-                        {
-                            return;
-                        }
-                        NSString key_Offline = new NSString("Offline");
-                        if (hiddenJsonDic.ContainsKey(key_Offline))
-                        {
-                            string signOut = hiddenJsonDic["Offline"].ToString();
-
-                            if (signOut == "0")
-                            {
-                                //涓嶄笅绾�
-                            }
-                            else
-                            {
-                                //寮哄埗涓嬬嚎
-                                //CommonPage.Instance.SingOut();
-                                HDLCommon.Current.ShowAlert(Language.StringByID(StringId.LoggedOnOtherDevices));
-                            }
-                        }
-                    }
-                }
+                HandleNotificationMessageUserInfo(userInfo, false);
             }
             else
             {
-                NSString key_hiddenJson = new NSString("HiddenJson");
-                if (userInfo.ContainsKey(key_hiddenJson))
-                {
-
-                    var hiddenJson = userInfo["HiddenJson"].ToString();
-                    if (string.IsNullOrEmpty(hiddenJson))
-                    {
-                        return;
-                    }
-
-                    if (hiddenJson.Contains("cmtID"))
-                    {
-                        /////鐩墠鏍规嵁杩欎釜鍒ゆ柇鏄惁鏄彲瑙嗗璁叉暟鎹�
-                        //VideoMethod(hiddenJson);
-                    }
-                    else
-                    {
-
-                        NSDictionary hiddenJsonDic = userInfo["HiddenJson"] as NSDictionary;
-                        if (hiddenJsonDic == null)
-                        {
-                            return;
-                        }
-                        NSString key_Offline = new NSString("Offline");
-                        if (hiddenJsonDic.ContainsKey(key_Offline))
-                        {
-                            string signOut = hiddenJsonDic["Offline"].ToString();
-
-                            if (signOut == "0")
-                            {
-                                //涓嶄笅绾�
-                            }
-                            else
-                            {
-                                //鏍囪涓嬬嚎
-                                haveToSignOut = true;
-                            }
-                        }
-                    }
-                }
+                //Inactive
+                HandleNotificationMessageUserInfo(userInfo, false);
 
             }
             completionHandler(UIBackgroundFetchResult.NewData);
@@ -269,12 +195,14 @@
             Console.WriteLine("OnActivated");
             base.OnActivated(application);
 
-            if (haveToSignOut == true)
-            {
-                //寮哄埗涓嬬嚎
-                //CommonPage.Instance.SingOut();
-                HDLCommon.Current.ShowAlert(Language.StringByID(StringId.LoggedOnOtherDevices));
-            }
+            //if (haveToSignOut == true)
+            //{
+                ////寮哄埗涓嬬嚎
+                //UserInfo.Current.LastTime = DateTime.MinValue;
+                //UserInfo.Current.headImagePagePath = "LoginIcon/2.png";//閲嶇疆鐢ㄦ埛澶村儚
+                //UserInfo.Current.SaveUserInfo();
+                //HDLCommon.Current.ShowAlert(Language.StringByID(StringId.LoggedOnOtherDevices));
+            //}
 
         }
 
@@ -342,64 +270,79 @@
         }
 
         /// <summary>
-        /// 閫�鍑虹櫥褰曟爣璁�
+        /// 澶勭悊閫氱煡娑堟伅
         /// </summary>
-        bool haveToSignOut;
+        void HandleNotificationMessageUserInfo(NSDictionary userInfo, bool bFinishedLaunching)
+        {
+            try
+            {
+                if (userInfo.ContainsKey(new NSString("aps")))
+                {
+                    var aps = userInfo["aps"] as NSDictionary;
+                    var alert = aps["alert"] as NSDictionary;
+                    var body = alert["body"] as NSString;
+                    var title = alert["title"] as NSString;
+                    var expandData = "";
+                    if (userInfo.ContainsKey(new NSString("expandData")))
+                    {
+                        expandData = userInfo["expandData"] as NSString;
+                    }
+                    var pushMes = new JPushMessageInfo()
+                    {
+                        Title = title,
+                        Content = body,
+                        Extras = expandData,
+                    };
+                    System.Console.WriteLine("PushMes title : " + pushMes.Title);
+                    System.Console.WriteLine("PushMes message : " + pushMes.Content);
+                    System.Console.WriteLine("PushMes extras : " + pushMes.Extras);
+
+                    if (bFinishedLaunching)
+                    {
+                        if (pushMes.Extras != null && pushMes.Extras.Contains("Offline"))
+                        {
+                            //haveToSignOut = true;
+                            //寮哄埗涓嬬嚎
+                            UserInfo.Current.LastTime = DateTime.MinValue;
+                            UserInfo.Current.headImagePagePath = "LoginIcon/2.png";//閲嶇疆鐢ㄦ埛澶村儚
+                            UserInfo.Current.SaveUserInfo();
+                            HDLCommon.Current.ShowAlert(Language.StringByID(StringId.LoggedOnOtherDevices));
+                        }
+                    }
+                    else
+                    {
+                        HDLCommon.Current.AdjustPushMessage(pushMes);
+                    }
+                   
+                }
+            }
+            catch
+            {
+
+            }
+        }
+
+        ///// <summary>
+        ///// 閫�鍑虹櫥褰曟爣璁�
+        ///// </summary>
+        //bool haveToSignOut;
         /// <summary>
-        /// 澶勭悊閫氱煡
+        /// 鍚姩APP 澶勭悊閫氱煡
         /// </summary>
         /// <param name="launchOptions"></param>
         void DealWithPushMes(NSDictionary launchOptions)
         {
-            haveToSignOut = false;
+            //haveToSignOut = false;
             if (launchOptions != null)
             {
                 // check for a remote notification
                 if (launchOptions.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey))
                 {
                     NSDictionary userInfo = launchOptions[UIApplication.LaunchOptionsRemoteNotificationKey] as NSDictionary;
+
                     if (userInfo != null)
                     {
-                        NSString key_hiddenJson = new NSString("HiddenJson");
-                        if (userInfo.ContainsKey(key_hiddenJson))
-                        {
-                            var hiddenJson = userInfo["HiddenJson"].ToString();
-                            if (!string.IsNullOrEmpty(hiddenJson))
-                            {
-                                if (hiddenJson.Contains("cmtID"))
-                                {
-
-                                    ///鐩墠鏍规嵁杩欎釜鍒ゆ柇鏄惁鏄彲瑙嗗璁叉暟鎹�
-                                    // VideoMethod(hiddenJson);
-                                }
-                                else
-                                {
-
-                                    NSDictionary hiddenJsonDic = userInfo["HiddenJson"] as NSDictionary;
-                                    if (hiddenJsonDic != null)
-                                    {
-                                        NSString key_Offline = new NSString("Offline");
-                                        if (hiddenJsonDic.ContainsKey(key_Offline))
-                                        {
-                                            string signOut = hiddenJsonDic["Offline"].ToString();
-
-                                            if (signOut == "0")
-                                            {
-                                                //涓嶄笅绾�
-                                            }
-                                            else
-                                            {
-                                                //鏍囪涓嬬嚎
-                                                haveToSignOut = true;
-                                            }
-                                        }
-
-                                    }
-                                }
-                            }
-
-
-                        }
+                        HandleNotificationMessageUserInfo(userInfo, true);
 
                     }
                 }
@@ -409,5 +352,6 @@
 
 
     }
+
 }
 

--
Gitblit v1.8.0