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

call native method from PCL failing Xamarin.From > 4

$
0
0

When trying to call a native method from my Shared Project (.NET Standard 2.0) to my iOS project. It not entering the CallToNativeMethod on my iOS project when using Xamarin.Forms version 4 or up. I followed this structure:

Shared Project

//Namespace 
//YourClass
public event EventHandler CallToNativeMethod;

public void RaiseCallToNativeMethod()
{
    if (CallToNativeMethod != null)
        CallToNativeMethod(this, new EventArgs());
    // C# 6 way (Does the same thing as the line above, but looks cleaner)
    // CallToNativeMethod?.Invoke(this, new EventArgs());
}

iOS / Android /etc. Renderer

//Namespace
//ClassOfRenderer
//Inside your OnElementChanged Method
((YourClass)Element).CallToNativeMethod += (sender, e) =>
{
    Control.YourNativeMethodIsCalledHere();
}

Back in Shared Project

var yourClass = new YourClass();
yourClass.RaiseCallToNativeMethod();

But the issue is that is not firing this part on the iOS Rendered:

  ((YourClass)Element).CallToNativeMethod += (sender, e) =>
    {
        Control.YourNativeMethodIsCalledHere();
    }

Do i need to do something different? Its working on Xamarin.Forms 3.6.0.539721


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>