From 06696e6f225733a60b03eea4a7c6374053d92c1d Mon Sep 17 00:00:00 2001 From: wxr <464027401@qq.com> Date: 星期二, 14 四月 2020 14:15:35 +0800 Subject: [PATCH] 20200414 --- 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