0

I got stuck in an issue when I was writing Xamarin Binding Library.

Prerequisites

  1. I have iOS Native Framework.
  2. I have a Xamarin Forms Application.

I have to write Xamarin Binding Library, which I am successfully able to write.

Now I got stuck

iOS Native Framework API (in MyClass.h) :-

-(void)clearAllDishes:(NSError * _Nullable * _Nullable)error;

Binding Code API (in ApiDefination.cs) :-

[BaseType(typeof(NSObject))]
public interface MyClass
{
    // -(void)clearAllDishes:(NSError * _Nullable * _Nullable)error;
    [Export("clearAllDishes:")]
    void ClearAllDishes([NullAllowed] out NSError error);
}

Now in Xamarin UI we have to call below method :-

try {
MyClass obj = new MyClass();
obj.clearAllDishes()
} catch throws Custom Exception {
   // Assuming the MyClass will throw the exception, when NSError pointer passed in iOS Native Framework.
}

Now my requirement is from Xamarin UI I have to call a method clearAllDishes() and further in Xamarin Library Binding I have to handle the clearAllDishes() in such a way so that we can throw the exception to Xamarin UI from here and call the iOS Native API clearAllDishes.

XPD
  • 1,121
  • 1
  • 13
  • 26
  • Out of curiosity, is there a reason it is a native method? If the original issue was finding a way to call a iOS specific logic from the Xamarin.Forms UI then using a DependencyService would help solve that probme – SomeStudent Jan 08 '20 at 14:28
  • Welcome to SO Apoorv! What issue are you seeing? Is the clearAllDishes() not accessible? Are you able to call that function in the AppDelegate file? – Saamer Jan 10 '20 at 21:37

0 Answers0