首页 > 解决方案 > 如何在 Xamarin.iOS 中使用共享

问题描述

我在这里关注文档:

https://docs.microsoft.com/en-us/xamarin/essentials/share?tabs=android

在我的 Xamarin.iOS 应用中实现共享功能。我的代码:

byte[] pdf = await DownloadPdfFile();

var fn = "myfile.pdf";
var file = Path.Combine(FileSystem.CacheDirectory, fn);
await File.WriteAllBytesAsync(file, pdf);

await Share.RequestAsync(new ShareFileRequest
{
    Title = ViewModel.Parameter.Title,
    File = new ShareFile(file)
});

运行此代码时没有任何反应。

标签: xamarinxamarin.ios

解决方案


我的猜测是您需要在 info.plist 中添加一些权限

<key>NSPhotoLibraryAddUsageDescription</key>
<string>This app needs access to the photo gallery for saving photos and videos.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This app needs access to photos gallery for saving photos and videos.</string>

如果您有任何疑问,请告诉我


推荐阅读