AMb AMb - 5 months ago 74
iOS Question

share image Xamarin Ios

I'm using Xamarin forms, and in my application has a button to share the problem that is being in my android application I got doing with Intent but in my application ios'm not knowing how to do, someone could help me?

using android

public async Task<bool> Share(ImageSource image)
Intent shareIntent = new Intent(Intent.ActionSend);

bitmapToShare = await GetBitmap (image);

if (bitmapToShare != null) {


var filePath = System.IO.Path.Combine (dir.AbsolutePath, string.Format("xpto_{0}.png",Guid.NewGuid()));
var stream = new FileStream (filePath, FileMode.Create);
bitmapToShare.Compress (Bitmap.CompressFormat.Png, 100, stream);
stream.Close ();

Java.IO.File file = new Java.IO.File (filePath);

shareIntent.SetType ("image/*");
shareIntent.PutExtra (Intent.ExtraStream, Android.Net.Uri.FromFile (file));
shareIntent.AddFlags (ActivityFlags.GrantReadUriPermission);
Forms.Context.StartActivity (Intent.CreateChooser (shareIntent, "Compartilhar"));

return true;

    private static async Task ShareImageAsyc(ImageSource image, string message, string url = null)
        var handler = image.GetHandler();

        if (handler == null) return;

        var uiImage = await handler.LoadImageAsync(image);

        var items = new List<NSObject> { new NSString(message ?? string.Empty) };
        if (!url.IsNullOrEmpty())
            items.Add(new NSString(url));

        var controller = new UIActivityViewController(items.ToArray(), null);

            .PresentViewController(controller, true, null);