问题描述
问题在于,当您启动应用程序时,会出现一个允许该位置的窗口,并且下面的逻辑停止运行。用户必须在启用后再次点击按钮才能执行代码中的逻辑。
如何在用户单击“允许一次”或“使用应用程序时始终允许”时执行逻辑,而无需再次按下按钮。
我的代码:
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 (将#修改为@)