c# - Xamarin iOS 上的位置权限问题
问题描述
问题是当您启动应用程序时,会出现一个允许定位的窗口,并且下面的逻辑停止运行。用户必须在启用后再次单击该按钮,然后执行代码中的逻辑。
当用户单击“允许一次”或“在使用应用程序时始终允许”时如何执行此操作,无需再次按下按钮即可执行逻辑。
我的代码:
async Task ButtonClickedGPS()
{
var status = await Permissions.CheckStatusAsync<Permissions.LocationWhenInUse>();
if (status == PermissionStatus.Denied && status == PermissionStatus.Disabled)
{
_ = await Permissions.RequestAsync<Permissions.LocationWhenInUse>();
}
else
{
try
{
var location = await Geolocation.GetLastKnownLocationAsync();
if (location != null)
{
WeatherBindingData weatherBindingData = await _restServiceForecast.GetWeatherDataForecast(GenerateRequestUriGPS(Constants.OpenWeatherMapEndpoint, location), GenerateRequestUriForecast(ConstantsForecast.OpenWeatherMapEndpoint2, _cityEntry), GenerateRequestUriAir(ConstantsAir.OpenWeatherMapEndpoint3, location));
_cityEntry.Text = CityName;
await DisplayHourlyForecast();
}
}
catch (FeatureNotSupportedException fnsEx)
{
// Handle not supported on device exception
}
catch (FeatureNotEnabledException fneEx)
{
// Handle not enabled on device exception
}
catch (PermissionException pEx)
{
// Handle permission exception
}
catch (Exception ex)
{
// Unable to get location
}
}
在我的 info.plist 我添加
Privacy - Location When In Use Usage Description
Privacy - Location Always Usage Description
Privacy - Location Always and When In Use Usage Description
但结果是一样的;(
有没有办法解决这个问题?
解决方案
推荐阅读
- javascript - 如何访问显示为未定义并直接引用它们但在控制台日志记录时正确显示的对象键?
- javascript - 本地复制运行但复制到网络服务器会导致 TypeError 不是函数的错误
- javascript - 是否可以重新定义基础对象 valueOf 以返回内部道具的值?
- python - 如何在两个地方之间创建距离矩阵
- python-2.7 - 为什么我收到“文件名、目录名或卷标语法不正确”。错误?
- excel - 格式化这个方程,我尝试了一些不起作用的东西
- java - 开始使用 libGDX - 项目生成器无法构建
- python - 为什么 set 运算符适用于 dict_key 视图对象而不适用于等效的 set 方法?
- neo4j - 使用 WHERE 查找平均关系数
- menu - 某些插入的图像上不会出现上下文内联菜单