1

我需要使用Xamarin.Essentials在 Xamarin.iOS 应用程序中请求权限。到目前为止,我发现的所有示例都是关于我没有使用的 Xamarin.Forms。

到目前为止,我发现的所有示例都是关于在按下按钮时询问权限,这对于实验来说很好,但对于生产应用程序却无用。

我有以下异步代码:

// TODO Move the permission requests to a more appropriate location?
var status = await Permissions.CheckStatusAsync<Permissions.Camera>();

if (status != PermissionStatus.Granted)
{
    status = await Permissions.RequestAsync<Permissions.Camera>();
}
status = await Permissions.CheckStatusAsync<Permissions.Microphone>();
{
    status = await Permissions.RequestAsync<Permissions.Microphone>();
}

我从 ViewDidLoad 异步覆盖中调用它。每当我调用 Permissions.RequestAsync() 时,应用程序就会崩溃并显示以下输出

2020-05-08 10:21:05.815 yaka[714:200964] error: * Assertion at /Users/builder/jenkins/workspace/archive-mono/2020-02/ios/release/mono/mini/debugger-agent.c:4568, condition `array->len == 1' not met
[PLCrashReport] plframe_cursor_read_dwarf_unwind_int:131: Failed to find FDE the current frame pc: 0x1014e7754: 8
[PLCrashReport] plframe_cursor_read_dwarf_unwind_int:131: Failed to find FDE the current frame pc: 0x101065470: 8
[PLCrashReport] plframe_cursor_read_dwarf_unwind_int:131: Failed to find FDE the current frame pc: 0x10123472c: 8
[PLCrashReport] plframe_cursor_read_dwarf_unwind_int:131: Failed to find FDE the current frame pc: 0x101064370: 8
[PLCrashReport] plframe_cursor_read_dwarf_unwind_int:131: Failed to find FDE the current frame pc: 0x1014ab360: 8
[PLCrashReport] plframe_cursor_read_dwarf_unwind_int:131: Failed to find FDE the current frame pc: 0x1015ac108: 8
[PLCrashReport] plframe_cursor_read_dwarf_unwind_int:131: Failed to find FDE the current frame pc: 0x1015592a0: 8
[PLCrashReport] plframe_cursor_read_dwarf_unwind_int:131: Failed to find FDE the current frame pc: 0x101559224: 8
[PLCrashReport] plframe_cursor_read_dwarf_unwind_int:131: Failed to find FDE the current frame pc: 0x10105f0c0: 8
[PLCrashReport] plframe_cursor_read_dwarf_unwind_int:131: Failed to find FDE the current frame pc: 0x1014ab360: 8
[PLCrashReport] plframe_cursor_read_dwarf_unwind_int:131: Failed to find FDE the current frame pc: 0x1014e7754: 8
[PLCrashReport] plframe_cursor_read_dwarf_unwind_int:131: Failed to find FDE the current frame pc: 0x101065470: 8
[PLCrashReport] plframe_cursor_read_dwarf_unwind_int:131: Failed to find FDE the current frame pc: 0x10123472c: 8
[PLCrashReport] plframe_cursor_read_dwarf_unwind_int:131: Failed to find FDE the current frame pc: 0x101064370: 8
[PLCrashReport] plframe_cursor_read_dwarf_unwind_int:131: Failed to find FDE the current frame pc: 0x1014ab360: 8
[PLCrashReport] plframe_cursor_read_dwarf_unwind_int:131: Failed to find FDE the current frame pc: 0x1015ac108: 8
[PLCrashReport] plframe_cursor_read_dwarf_unwind_int:131: Failed to find FDE the current frame pc: 0x1015592a0: 8
[PLCrashReport] plframe_cursor_read_dwarf_unwind_int:131: Failed to find FDE the current frame pc: 0x101559224: 8
[PLCrashReport] plframe_cursor_read_dwarf_unwind_int:131: Failed to find FDE the current frame pc: 0x10105f0c0: 8
[PLCrashReport] plframe_cursor_read_dwarf_unwind_int:131: Failed to find FDE the current frame pc: 0x1014ab360: 8

我的 info.plist 包含以下有关权限的内容:

<key>NSCameraUsageDescription</key>
<string>L&apos;accès est réservé au vidéoconférences.</string>
<key>NSMicrophoneUsageDescription</key>
<string>L&apos;accès est réservé au vidéoconférences.</string>

必须有适当的位置才能安全地调用此编码,但我无法弄清楚。

任何帮助表示赞赏。

4

1 回答 1

0

您不需要针对 iOS 的特定代码。这就是Essentials的美妙之处。它利用了所谓的诱饵和开关模式。简而言之 - 每个平台的公开代码都是相同的,并且在编译时只会编译您需要的代码。您可以在此处查看权限代码。

如果您查看Xamarin.Essentials.csproj广告,您会看到如果项目以 iOS 为目标,则只会*.ios构建带有后缀的 cs 文件。然后,在运行时,将调用适当的代码。

很可能,您在不正确的地方调用它。尝试调用它ViewDidAppear,因为这个错误听起来像 Xamarin 期望某些东西已经完全加载/可见,但事实并非如此。

总而言之-您可以使用可以在每个平台的官方文档页面上找到的代码示例,而不会出现任何问题。只是要小心你打电话给他们的确切位置。

于 2020-05-16T18:45:06.867 回答