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

Wait for Device.BeginInvokeOnMainThread

$
0
0

Hello,

I have an interface IPicture which I uses on Android and iOS.

I implemented with dependecy service a way to save a photo in device.

Here is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Foundation;
using UIKit;
using System.IO;
using System.Threading.Tasks;
using System;
using Xamarin.Forms;


[assembly: Xamarin.Forms.Dependency(typeof(MyApp.iOS.Picture_iOS))]

namespace MyApp.iOS
{
    public class Picture_iOS: IPicture
    {
        public Int16 SavePictureToDisk(string filename, byte[] imageData)
        {
            var chartImage = new UIImage (NSData.FromArray (imageData));
            Int16 response = 0;


            Device.BeginInvokeOnMainThread (() => {


                chartImage.SaveToPhotosAlbum ((image, error) => {
                    //you can retrieve the saved UI Image as well if needed using
                    //var i = image as UIImage;
                    if (error != null) {
                        Console.WriteLine (error.ToString ());
                        response = 0;
                    } else
                        response = 1;
                });
            });

            return response;
        }
    }
}

My problem is that I need it to return a Int16 as response... but just after the Device.BeginInvokeOnMainThread runs...

I can't use await because it is void...

How I can do that?


Viewing all articles
Browse latest Browse all 91519

Trending Articles