2015-07-09 2 views
1

Я использую формы Xamarin, и в моем приложении есть кнопка, чтобы поделиться проблемой, которая находится в моем приложении Android, я получил работу с Intent, но в своем приложении ios'm не знал, как это сделать, кто-то может мне помочь?share image Xamarin 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; 
    } 
+1

https://developer.xamarin.com/samples/monotouch/ios8/Share/ – Jason

ответ

1
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