gpt4 book ai didi

ios - GetPositionAsync 适用于 android 但不适用于 IOS 11

转载 作者:行者123 更新时间:2023-11-29 11:40:04 25 4
gpt4 key购买 nike

System.Threading.Tasks.TaskCanceledException: A task was canceled.

2017-11-05 14:46:31.228 Project.iOS[36807:4480015]
Unhandled Exception:
System.Threading.Tasks.TaskCanceledException: A task was canceled.
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00020] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:179
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
at System.Runtime.CompilerServices.TaskAwaiter`

当我尝试在 ios.11 模拟器上调试时,我很难处理以下代码抛出的异常,但这段代码在 android 中运行良好。

private async Task<Plugin.Geolocator.Abstractions.Position> GetPositionAsync() {
var locator = CrossGeolocator.Current;
locator.DesiredAccuracy = 50;
TimeSpan ts = new TimeSpan((Int32)10000);
_position = await locator.GetPositionAsync(timeout: ts);
return _position;
}

我已经按照与@jamesmontemagno/Xamarin.Plugins/Geolocator/相关的各种网站中提到的所有说明进行操作,但没有成功。我确保我的 info.plist 包含以下代码:

  <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>This app needs access location when open and in the background.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Need location for geolocator plugin.</string>
<key>RequestWhenInUseAuthorization</key>
<string>Need location for geolocator plugin.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Need location for geolocator plugin.</string>

我想要实现的是通过 Xamarin.Froms 在所有三个平台(IOS、Android、Windows)上获取当前位置。 Android 运行良好,但 IOS 是我卡住的地方。感谢任何类型的帮助。

最佳答案

和官方的sample对比后,发现问题是你设置的timeout参数太短,无法完成任务,所以每次都cancel了。

解决方案:

await locator.GetPositionAsync(TimeSpan.FromSeconds(10));

关于ios - GetPositionAsync 适用于 android 但不适用于 IOS 11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47125984/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com