ios - 分享图片 Xamarin Ios

标签 ios xamarin xamarin.forms

我正在使用 Xamarin 表单,并且在我的应用程序中有一个按钮可以分享我使用 Intent 处理的 Android 应用程序中出现的问题,但在我的应用程序 ios 中不知道该怎么做,有人可以帮助我?

使用安卓

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

        bitmapToShare = await GetBitmap (image);

        if (bitmapToShare != null) {

            CreateDirectoryForPictures("Xpto");

            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));
        items.Add(uiImage);

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

        UIApplication.SharedApplication.KeyWindow.RootViewController.GetTopViewController()
            .PresentViewController(controller, true, null);
    }

来自:https://github.com/jimbobbennett/JimLib.Xamarin/blob/master/JimLib.Xamarin.ios/Sharing/Share.cs

关于ios - 分享图片 Xamarin Ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31323886/

相关文章:

ios - 如何为 iPhone 6 和 6 Plus 上的应用启用原生分辨率?

ios - 操作按钮在前台显示应用程序

c# - 如何从 Xamarin.Forms 中的可移植类库项目调用位于 Android 项目内部的方法?

c# - Xamarin.Forms 的分辨率相关的 FontSize

c# - Xamarin.Forms:独立于平台的应用程序菜单

ios - 找不到开发人员磁盘镜像

ios - 该算法如何计算 rgb 颜色?

android - Webview 和 iFrame 视频全屏问题

Android MVVM Cross v3 - 如何创建具有交替行颜色的 ListView

android - 带换行符的多行 TextView