Xamarin.Forms Launcher.OpenAsync for images and files (iOS)

David Strachan 26 Reputation points
2021-03-08T13:37:55.09+00:00

I am looking at a way to have a generic file launcher option within my application, the file types are not limited so you could have jpg, png, docx, txt, and other formats.

Currently I have this global method for both iOS and Android:

public async Task XamarinLaunch(string filePath)
{
await Launcher.OpenAsync(new OpenFileRequest
{
File = new ReadOnlyFile(filePath)
});
}

My issue is that in iOS .txt, .jpg and .png do not have an application to open by default. So this leave the user experience lacking and they are not able to launch the attachment natively. Is this the correct way to do this? Ideally I was wanting to have the launch attachment in a shared code that was not native, but is this achievable in iOS?

The desired approach can be to just preview the attachment, though launching in an external external application would be desirable .

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,295 questions
{count} vote