Xamarin Forms iOS – Receive an image or PDF from another application

I need to make my application created in Xamarin Forms, appear in the list of applications available for sharing.

Example: let’s say my app is called App123. I’m on Google Photos, I click on an image, I click on share, the list of available apps appears (Instagram, WhatsApp, Facebook, LinkedIn), I want App123 to appear here too. So far it’s ok.

The problem is that I can’t save and get the image or PDF being received on iOS.

Currently, my code looks like this:

public class ShareViewController : SLComposeServiceViewController
{
    protected ShareViewController(IntPtr handle) : base(handle) { }

    public override void DidReceiveMemoryWarning()
    {
        base.DidReceiveMemoryWarning();
    }

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();
    }

    public override bool IsContentValid()
    {
        return true;
    }

    public override void DidSelectPost()
    {
        if (ExtensionContext.InputItems != null)
        {
            NSExtensionItem item = ExtensionContext.InputItems[0];

            if (item.Attachments != null && item.Attachments.Length > 0)
            {
                foreach (NSItemProvider itemProvider in item.Attachments)
                {
                    if (itemProvider.HasItemConformingTo(UTType.Image))
                    {
                        itemProvider.LoadItem(UTType.Image, null, (NSObject itemObject, NSError error) =>
                        {
                            NSData imgData = null;

                            if (itemObject is UIImage)
                            {
                                using (imgData = ((UIImage)itemObject).AsPNG())
                                {
                                    byte[] myByteArray = new byte[imgData.Length];
                                    Marshal.Copy(imgData.Bytes, myByteArray, 0, Convert.ToInt32(imgData.Length));

                                    var fileIOS = new FileIOS();
                                    fileIOS.WriteAllBytes("Test123.png", myByteArray);
                                }
                            }
                        });
                    }
                }
            }
        }
    }

    public override SLComposeSheetConfigurationItem[] GetConfigurationItems()
    {
        // To add configuration options via table cells at the bottom of the sheet, return an array of SLComposeSheetConfigurationItem here.
        return new SLComposeSheetConfigurationItem[0];
    }
}

FileIOS

public class FileIOS
{
    public string GetFilePath(string filename)
    {
        return Path.Combine(Path.GetTempPath(), filename);
    }

    public bool Exists(string filename)
    {
        string filepath = GetFilePath(filename);
        return File.Exists(filepath);
    }

    public void WriteAllBytes(string fileName, byte[] content)
    {
        string filePath = string.Empty;

        try
        {
            filePath = GetFilePath(fileName);
            File.WriteAllBytes(filePath, content);
        }
        catch (Exception exception)
        {
            throw new Exception("Error " + filePath, exception);
        }
    }
}

Full source code is available in this link: https://drive.google.com/file/d/1zj6Z80A2X7k8IJdKSoeVBbBfSiNJulf7/view?usp=sharing

Could someone help me please?
Thank you very much!

Source: Xamarin.ios Questions