【发布时间】: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();
谢谢
【问题讨论】: