如何解决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
但结果是一样的;(
有没有办法解决这个问题?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。