Search code examples
xamarinxamarin.iosmvvmcross

Unable to share text into email or sms in Xamarin iOS app


I'm trying to implement service in C# that allows me to share string to exisiting applcation in my iOS system (for example start email app with my string text or sms app). To do this I have beeen implemented class that should do this. Here is the code:

public class IphoneShareService : IShareService
{
    public void Share(string content)
    {
        var text = NSObject.FromObject(content);
        var items = new[] { text };
        var activity = new UIActivityViewController(items, null);
        UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(activity, true, null);
    }
}

The problem is that, when I call PresentViewController method with parameters (string), i don't have any options, where I can send my text. This is example screenshot after call PresentViewController in my application:

enter image description here

So i don't know what is the problem actually ? I need to setup some special code to mark my PresentViewController to show specified application where I can share my text ?


Solution

  • iOS simulator does not have SMS or Email apps installed. Therefor you don't see these options. The code shared above should work as expected on a real device. So test the application on a real device instead of the simulator.