Share button on Xamarin.forms.ios

I'm starting on Xamarin ant trying to create a simple application with Xamarin.forms. Now I need to add the share button (square + arrow, like on Safari on the iPhone) in my application. As I know, Android and IOS are different from each other, so I use DependencyService. It works fine on Android using Intent, but cannot do it on iOS. could you help me please. Thanks everyone, this is my code.

PCL

    var x = DependencyService.Get<IShareable>(); 
    x.ShareText("any text to share"); 

Android

public void ShareText(string textToShear) 
{
  var myIntent = new Intent(Android.Content.Intent.ActionSend);      
  myIntent.SetType("text/plain"); 
  myIntent.PutExtra("sms_body", textToShear); 
  Forms.Context.StartActivity(Intent.CreateChooser(myIntent,"Choose an App"));
}

IOS

public void ShareText(string textToShear) 
{
 //what i should do 
} 
+4
source share
2 answers

You want to use the UIActivityViewController .

It will look something like this:

public void ShareText(string textToShare) 
{
    var activityController = new UIActivityViewController(new NSObject[] { UIActivity.FromObject(textToShare) }, null);
    UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(activityController, true, null);
}
+2

.

, :

  • iOS -, Sharekit, , Xamarin.Forms
  • iOS 6 c, , #/Xamarin.
  • Xamarin, Xamarin.Social, . , , ... , Android.

, . , , .

+1

All Articles