How to use Share in Xamarin.iOS


I am following the documentation here:

To implement the share functionality in my Xamarin.iOS app. My code:

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)

Nothing happens when I run this code.


I solved it. There is a bug when running on iPad as mentioned here and you can fix this by specifying the PresentationSourceBounds:

await Share.RequestAsync(new ShareFileRequest
    Title  "My title",
    File  new ShareFile(file),
    PresentationSourceBounds  new System.Drawing.Rectangle((int)View.Frame.Width, 0, (int)(View.Frame.Width), (int)(View.Frame.Height))

Answered By – Drake

Leave a Comment