我正在使用 Xamarin.Forms 并创建一个 iOS 应用程序,该应用程序具有后台服务以每 10 分钟获取一次位置。
代码正在运行,我的问题是当我在 iPad 上访问应用程序配置时。
它显示访问相机但不访问当前位置的权限。
我认为当我提交应用程序进行审核时,这将是一个问题。
初始化位置:
this.locMgr = new CLLocationManager();
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
{
locMgr.RequestAlwaysAuthorization(); // works in background
//locMgr.RequestWhenInUseAuthorization (); // only in foreground
}
获取位置:
if (CLLocationManager.LocationServicesEnabled)
{
if (CLLocationManager.Status==CLAuthorizationStatus.Authorized
|| CLLocationManager.Status==CLAuthorizationStatus.AuthorizedAlways)
{
//set the desired accuracy, in meters
LocMgr.DesiredAccuracy = 1;
LocMgr.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) =>
{
_currentLocation = (e.Locations[e.Locations.Length - 1]);
};
LocMgr.AuthorizationChanged += (object sender, CLAuthorizationChangedEventArgs e) =>
{
if (e.Status == CLAuthorizationStatus.Denied
|| e.Status == CLAuthorizationStatus.Restricted)
{
LocMgr.StopUpdatingLocation();
_currentLocation = null;
}
};
LocMgr.StartUpdatingLocation();
}
}
有什么我忘记了吗?
最佳答案
您是否将这些键添加到您的 Info.plist 文件中?
<key>NSLocationAlwaysUsageDescription</key>
<string>Your message goes here</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Your message goes here</string>
关于ios - xamarin 形成使用位置 iOS 的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29898277/