private void CameraCaptureTaskOnCompleted(object sender, PhotoResult photoResult)
        {
            if (photoResult.TaskResult == TaskResult.None)
            {
                tcs.TrySetException(photoResult.Error);
                return;
            }

            if (photoResult.TaskResult == TaskResult.Cancel)
            {
                tcs.TrySetResult(null);
                return;
            }

            CameraResult result = new CameraResult();
            result.Picture = ImageSource.FromStream(() => photoResult.ChosenPhoto);
            result.FilePath = photoResult.OriginalFileName;

            tcs.TrySetResult(result);
        }
        public static void OnResult(Result resultCode)
        {
            if (resultCode == Result.Canceled)
            {
                tcs.TrySetResult(null);
                return;
            }

            if (resultCode != Result.Ok)
            {
                tcs.TrySetException(new Exception("Unexpected error"));
                return;
            }

            CameraResult res = new CameraResult();
            res.Picture = ImageSource.FromFile(file.Path);
            res.FilePath = file.Path;

            tcs.TrySetResult(res);
        }
        public Task<CameraResult> TakePictureAsync()
        {
            var tcs = new TaskCompletionSource<CameraResult>();

            Camera.TakePicture(UIApplication.SharedApplication.KeyWindow.RootViewController, (imagePickerResult) => {

                if (imagePickerResult == null)
                {
                    tcs.TrySetResult(null);
                    return;
                }

                var photo = imagePickerResult.ValueForKey(new NSString("UIImagePickerControllerOriginalImage")) as UIImage;

                // You can get photo meta data with using the following
                // var meta = obj.ValueForKey(new NSString("UIImagePickerControllerMediaMetadata")) as NSDictionary;

                var documentsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                string jpgFilename = Path.Combine(documentsDirectory, Guid.NewGuid() + ".jpg");
                NSData imgData = photo.AsJPEG();
                NSError err = null;

                if (imgData.Save(jpgFilename, false, out err))
                {
                    CameraResult result = new CameraResult();
                    result.Picture = ImageSource.FromStream(imgData.AsStream);
                    result.FilePath = jpgFilename;

                    tcs.TrySetResult(result);
                }
                else
                {
                    tcs.TrySetException(new Exception(err.LocalizedDescription));
                }
            });

            return tcs.Task;
        }