【问题标题】:Xamarin Forms iOS Location Permission(Always Allow)Xamarin 表单 iOS 位置权限(始终允许)
【发布时间】:2019-06-20 15:05:28
【问题描述】:

我在我的 iOS Xamarin Forms 应用程序中使用(始终允许)位置权限。我今天面临的问题是,每当发生位置事件时,我都无法充分利用 ALWAYS 权限来在后台恢复我的应用程序(已经被杀死)。有什么解决方案吗?

我的代码:

lm = new CLLocationManager
           {
               PausesLocationUpdatesAutomatically = false,
               DesiredAccuracy=CLLocation.AccuracyBest,
               DistanceFilter=0,
               AllowsBackgroundLocationUpdates = true
           };


           lm.LocationsUpdated +=
               (object sender, CLLocationsUpdatedEventArgs e) => {
                   var locations = e.Locations; 
                   LocationEventArgs args = new LocationEventArgs();
                   args.lat = locations[locations.Length - 1].Coordinate.Latitude;
                   args.lng = locations[locations.Length - 1].Coordinate.Longitude;
                   locationObtained(this, args);  //Log
               };
           lm.AuthorizationChanged += (object sender,
               CLAuthorizationChangedEventArgs e) => {
                   if (e.Status == CLAuthorizationStatus.Authorized)
                   {
                       //lm.StartMonitoringSignificantLocationChanges();
                       lm.StartUpdatingLocation();
                   }
               };
           lm.RequestAlwaysAuthorization();

谢谢

【问题讨论】:

    标签: xamarin.forms xamarin.ios


    【解决方案1】:

    我今天面临的问题是,无论何时发生位置事件,我都无法充分利用 ALWAYS 权限来在后台恢复我的应用程序(已经被杀死)。

    如果 APP 终止,AllowsBackgroundLocationUpdates 将不起作用。你应该确保应用程序没有被首先杀死。

    allowsBackgroundLocationUpdates :一个布尔值,指示应用程序在挂起时是否应接收位置更新。(未终止状态)。

    【讨论】:

      猜你喜欢
      • 2021-05-27
      • 2021-07-03
      • 2020-07-15
      • 1970-01-01
      • 1970-01-01
      • 2020-01-26
      • 2015-02-10
      • 2021-10-24
      • 1970-01-01
      相关资源
      最近更新 更多