From 7167334c0e89dd84827d59e726123d14776e3a09 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期二, 16 六月 2020 11:14:13 +0800
Subject: [PATCH] 2020-06-16-1

---
 Shared.IOS/BaseApplicationDelegate.cs |   75 ++++++++++++++++++-------------------
 1 files changed, 36 insertions(+), 39 deletions(-)

diff --git a/Shared.IOS/BaseApplicationDelegate.cs b/Shared.IOS/BaseApplicationDelegate.cs
index 8ae820b..95d4a1c 100644
--- a/Shared.IOS/BaseApplicationDelegate.cs
+++ b/Shared.IOS/BaseApplicationDelegate.cs
@@ -25,7 +25,6 @@
             //Volume.Init();
 
             FinishedLaunchingAction?.Invoke(application, launchOptions);
-         /*
             //GPS
             if (Shared.Application.IsGpsEnable)
             {
@@ -53,7 +52,6 @@
                     ///TODO 鍙互鎻愮ず鐢ㄦ埛鎵撳紑瀹氫綅鏉冮檺
                 }
             }
-            */
             return true;
         }
 
@@ -77,9 +75,10 @@
                 application.RegisterForRemoteNotificationTypes(UIRemoteNotificationType.NewsstandContentAvailability | UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound);
             }
         }
-        /*
+        
         class MyCLLocationManager : CLLocationManager
         {
+            #region 瀹氫綅
             public static MyCLLocationManager Instance
             {
                 get
@@ -89,12 +88,11 @@
                         locationManager = new MyCLLocationManager();
                         //璁剧疆鏄惁鍏佽绯荤粺鑷姩鏆傚仠瀹氫綅
                         locationManager.PausesLocationUpdatesAutomatically = false;
-                        locationManager.AllowsBackgroundLocationUpdates = true;
+                        locationManager.AllowsBackgroundLocationUpdates = false;
                         //璁剧疆瀹氫綅绮惧害
                         locationManager.DesiredAccuracy = CLLocation.AccuracyKilometer;
                         locationManager.init();
                     }
-
                     return locationManager;
                 }
             }
@@ -120,22 +118,23 @@
                     locationManager.LocationsUpdated += (sender, e) =>
                     {
                         var location = e.Locations[e.Locations.Length - 1];
-                        //adjustDistanceFilter(location);
+                        adjustDistanceFilter(location);
+                        Shared.Application.LocationAction?.Invoke(location.Coordinate.Longitude, location.Coordinate.Latitude);
                         //System.Console.WriteLine($"浣嶇疆淇℃伅鍙樺寲 缁忓害{location.Coordinate.Longitude}  绾害{location.Coordinate.Latitude}");
-                        uploadToServer(location);
+                        //uploadToServer(location);
                     };
 
                 }
             }
             
-    //*  瑙勫垯: 濡傛灉閫熷害灏忎簬minSpeed m/s 鍒欐妸瑙﹀彂鑼冨洿璁惧畾涓�100m
-    //*  鍚﹀垯灏嗚Е鍙戣寖鍥磋瀹氫负minSpeed*minInteval
-    //*  姝ゆ椂鑻ラ�熷害鍙樺寲瓒呰繃10% 鍒欐洿鏂板綋鍓嶇殑瑙﹀彂鑼冨洿(杩欓噷闄愬埗鏄洜涓轰笉鑳戒笉鍋滅殑璁剧疆distanceFilter,
-    //*  鍚﹀垯uploadLocation浼氫笉鍋滆瑙﹀彂)
+            //*  瑙勫垯: 濡傛灉閫熷害灏忎簬minSpeed m/s 鍒欐妸瑙﹀彂鑼冨洿璁惧畾涓�100m
+            //*  鍚﹀垯灏嗚Е鍙戣寖鍥磋瀹氫负minSpeed*minInteval
+            //*  姝ゆ椂鑻ラ�熷害鍙樺寲瓒呰繃10% 鍒欐洿鏂板綋鍓嶇殑瑙﹀彂鑼冨洿(杩欓噷闄愬埗鏄洜涓轰笉鑳戒笉鍋滅殑璁剧疆distanceFilter,
+            //*  鍚﹀垯uploadLocation浼氫笉鍋滆瑙﹀彂)
 
             void adjustDistanceFilter(CLLocation location)
             {
-                //    NSLog(@"adjust:%f",location.speed);
+                //NSLog(@"adjust:%f",location.speed);
                 if (location.Speed < minSpeed)
                 {
                     if (Math.Abs(DistanceFilter - minInteval) > 0.1f)
@@ -173,34 +172,32 @@
                 }
             }
 
-            void uploadToServer(CLLocation location) {
-#warning 濡傛灉鏈夎緝闀挎椂闂寸殑鎿嶄綔 姣斿HTTP涓婁紶 璇蜂娇鐢╞eginBackgroundTaskWithExpirationHandler
-                if (UIApplication.SharedApplication.ApplicationState == UIApplicationState.Active)
-                {
-                    //HTTP upload
-                    Shared.Application.LocationAction?.Invoke(location.Coordinate.Longitude, location.Coordinate.Latitude);
-
-                    endBackgroundUpdateTask();
-                }
-                else//鍚庡彴瀹氫綅
-                {
-                    //鍋囧涓婁竴娆$殑涓婁紶鎿嶄綔灏氭湭缁撴潫 鍒欑洿鎺eturn
-                    if (taskIdentifier != UIApplication.BackgroundTaskInvalid)
-                    {
-                        return;
-                    }
-
-                    beingBackgroundUpdateTask();
-
-                    //HTTP upload
-                    Shared.Application.LocationAction?.Invoke(location.Coordinate.Longitude, location.Coordinate.Latitude);
-
-                    //涓婁紶瀹屾垚璁板緱璋冪敤
-                    endBackgroundUpdateTask();
-                }
-            }
+//            void uploadToServer(CLLocation location)
+//            {
+//#warning 濡傛灉鏈夎緝闀挎椂闂寸殑鎿嶄綔 姣斿HTTP涓婁紶 璇蜂娇鐢╞eginBackgroundTaskWithExpirationHandler
+//                if (UIApplication.SharedApplication.ApplicationState == UIApplicationState.Active)
+//                {
+//                    //HTTP upload
+//                    Shared.Application.LocationAction?.Invoke(location.Coordinate.Longitude, location.Coordinate.Latitude);
+//                    endBackgroundUpdateTask();
+//                }
+//                else//鍚庡彴瀹氫綅
+//                {
+//                    //鍋囧涓婁竴娆$殑涓婁紶鎿嶄綔灏氭湭缁撴潫 鍒欑洿鎺eturn
+//                    if (taskIdentifier != UIApplication.BackgroundTaskInvalid)
+//                    {
+//                        return;
+//                    }
+//                    beingBackgroundUpdateTask();
+//                    //HTTP upload
+//                    Shared.Application.LocationAction?.Invoke(location.Coordinate.Longitude, location.Coordinate.Latitude);
+//                    //涓婁紶瀹屾垚璁板緱璋冪敤
+//                    endBackgroundUpdateTask();
+//                }
+//            }
+            #endregion
         }
-    */
+
         public override void OnResignActivation(UIApplication application) => OnResignActivationAction?.Invoke(application);// Invoked when the application is about to move from active to inactive state.// This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) // or when the user quits the application and it begins the transition to the background state.// Games should use this method to pause the game.
 
         public override void DidEnterBackground(UIApplication application) => DidEnterBackgroundAction?.Invoke(application);// Use this method to release shared resources, save user data, invalidate timers and store the application state.// If your application supports background exection this method is called instead of WillTerminate when the user quits.

--
Gitblit v1.8.0