Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Call UIImagePickerController from Xamarin.Forms portable

$
0
0

Hi,
I have a Xamarin Forms app where all the UI is in a portable library. I'm trying to add functionality to pick a photo from the device so for this I have an interface class in my portable library and separate implementations in the Android and iOS projects. I've got the Android code working but I can't get the UIImagePickerController to display. Here is my interface class, I pass the sender ContentPage to the SelectPhoto function:

public interface IInterfaceFeatureService
{
    bool SelectPhoto(ContentPage Page);
}

and here is my iOS implementation:

class iOSFeatureService : IInterfaceFeatureService
{
    public bool SelectPhoto(ContentPage Page)
    {
        bool bRet = false;

        var imagePicker = new UIImagePickerController { SourceType = UIImagePickerControllerSourceType.Camera };

        imagePicker.FinishedPickingMedia += (sender, ev) =>
        {
            //var filepath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "tmp.png");
            //var image = (UIImage)ev.Info.ObjectForKey(new NSString("UIImagePickerControllerOriginalImage"));
            //DismissViewController(true, null)
        };

        imagePicker.Canceled += (sender, ev2) => 
        {
            //DismissViewController(true, null)
        };

        Page.CreateViewController().PresentModalViewController(imagePicker, true);

        return bRet;
    }
}

Everything compiles OK and the iOS implementation of SelectPhoto is called but nothing appears on screen. What am I doing wrong?

SteveR


Viewing all articles
Browse latest Browse all 91519

Trending Articles