Forum Xamarin.Forms

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Xamarin forms - IOS image does not share to whatsapp and Facebook

I have xamarin forms application. It has a feature to share captured/galary images. It works well for Xamarin Android but for Xamarin IOS while i share images to whatsapp/facebook then it shares only text and skip sharing image.
Please check below code and suggest if it can be fixed:

public async Task Share(string title, string message, ImageSource imageSource)
{

        IImageSourceHandler handler;
        if (imageSource is FileImageSource)
            handler = new FileImageSourceHandler();
        else if (imageSource is StreamImageSource)
            handler = new StreamImagesourceHandler();
        else if (imageSource is UriImageSource)
            handler = new ImageLoaderSourceHandler();
        else
            throw new NotImplementedException();
        var uiImage = await handler.LoadImageAsync(imageSource);
        var img = NSObject.FromObject(uiImage);


       // var items = new NSObject[] { NSObject.FromObject(message), img };
        var items = new NSObject[] {  img };
        var activityController = new UIActivityViewController(items, null);
        var vc = GetVisibleViewController();

        NSString[] excludedActivityTypes = null;

        if (excludedActivityTypes != null && excludedActivityTypes.Length > 0)
            activityController.ExcludedActivityTypes = excludedActivityTypes;

        if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
        {
            if (activityController.PopoverPresentationController != null)
            {
                activityController.PopoverPresentationController.SourceView = vc.View;
            }
        }
        await vc.PresentViewControllerAsync(activityController, true);
    }

    UIViewController GetVisibleViewController()
    {
        var rootController = UIApplication.SharedApplication.KeyWindow.RootViewController;

        if (rootController.PresentedViewController == null)
            return rootController;

        if (rootController.PresentedViewController is UINavigationController)
        {
            return ((UINavigationController)rootController.PresentedViewController).TopViewController;
        }

        if (rootController.PresentedViewController is UITabBarController)
        {
            return ((UITabBarController)rootController.PresentedViewController).SelectedViewController;
        }

        return rootController.PresentedViewController;
    }
} 

Thanks,

Posts

  • jessdonatellijessdonatelli Member ✭✭

    Did you figure out what your issue was? I'm having the same problem. Shares both text and image to WhatsApp on Xamarin.Android, but only text on Xamarin.iOS.

  • jessdonatellijessdonatelli Member ✭✭

    For anyone else that may see this...I shared null for the text and kept the image and that made it work. Seems like WhatsApp only lets you do one or the other on iOS.

Sign In or Register to comment.