From f6fd8acd7c53c44187e70b4709443318a628f4b5 Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期二, 16 六月 2020 13:12:33 +0800
Subject: [PATCH] 2020-06-016

---
 Shared.IOS/BaseApplicationDelegate.cs |   87 +++++++++++++++++++++++--------------------
 1 files changed, 47 insertions(+), 40 deletions(-)

diff --git a/Shared.IOS/BaseApplicationDelegate.cs b/Shared.IOS/BaseApplicationDelegate.cs
index 95d4a1c..904144b 100644
--- a/Shared.IOS/BaseApplicationDelegate.cs
+++ b/Shared.IOS/BaseApplicationDelegate.cs
@@ -21,10 +21,15 @@
         public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
         {
             registerForRemoteNotification(application);
-            //var musicInfo = new MusicInfo { };
-            //Volume.Init();
+
+            if (Shared.Application.IsMusicEnable)
+            {
+                var musicInfo = new MusicInfo { };
+                Volume.Init();
+            }
 
             FinishedLaunchingAction?.Invoke(application, launchOptions);
+         
             //GPS
             if (Shared.Application.IsGpsEnable)
             {
@@ -52,6 +57,7 @@
                     ///TODO 鍙互鎻愮ず鐢ㄦ埛鎵撳紑瀹氫綅鏉冮檺
                 }
             }
+
             return true;
         }
 
@@ -75,10 +81,9 @@
                 application.RegisterForRemoteNotificationTypes(UIRemoteNotificationType.NewsstandContentAvailability | UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound);
             }
         }
-        
+
         class MyCLLocationManager : CLLocationManager
         {
-            #region 瀹氫綅
             public static MyCLLocationManager Instance
             {
                 get
@@ -88,11 +93,12 @@
                         locationManager = new MyCLLocationManager();
                         //璁剧疆鏄惁鍏佽绯荤粺鑷姩鏆傚仠瀹氫綅
                         locationManager.PausesLocationUpdatesAutomatically = false;
-                        locationManager.AllowsBackgroundLocationUpdates = false;
+                        locationManager.AllowsBackgroundLocationUpdates = true;
                         //璁剧疆瀹氫綅绮惧害
                         locationManager.DesiredAccuracy = CLLocation.AccuracyKilometer;
                         locationManager.init();
                     }
+
                     return locationManager;
                 }
             }
@@ -118,23 +124,22 @@
                     locationManager.LocationsUpdated += (sender, e) =>
                     {
                         var location = e.Locations[e.Locations.Length - 1];
-                        adjustDistanceFilter(location);
-                        Shared.Application.LocationAction?.Invoke(location.Coordinate.Longitude, location.Coordinate.Latitude);
-                        //System.Console.WriteLine($"浣嶇疆淇℃伅鍙樺寲 缁忓害{location.Coordinate.Longitude}  绾害{location.Coordinate.Latitude}");
-                        //uploadToServer(location);
+                        //adjustDistanceFilter(location);
+                        //Shared.HDLUtils.WriteLine($"浣嶇疆淇℃伅鍙樺寲 缁忓害{location.Coordinate.Longitude}  绾害{location.Coordinate.Latitude}");
+                        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)
@@ -172,30 +177,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();
-//                }
-//            }
-            #endregion
+            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();
+                }
+            }
         }
 
         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.

--
Gitblit v1.8.0