How to make iOS native libraries accessible in Xamarin apps?

Technology CommunityCategory: XamarinHow to make iOS native libraries accessible in Xamarin apps?
VietMX Staff asked 3 years ago

Xamarin.iOS supports linking with both native C libraries and Objective-C libraries.

For linking with third-party C libraries, it is required that all the libraries be linked statically.

Following are the steps one needs to follow to consume third party C Libraries:

  • Bring the Library into your project: Select your project from the Solution Explorer and locate the file on your disk and add it to the project. When prompted, tell Visual Studio for Mac or Visual Studio to copy it into the project. After adding it, find the library in the project, right-click on it, and set the Build Action to none.
  • Configure Xamarin.iOS to link the library: Now on the project options of your project,  add in iOS Build’s extra argument, the “-gcc_flags” option followed by a quoted string that contains all the third-party libraries that are required for your project
  • Access the methods from the library: For this,  use Mono’s Platform Invoke (P/Invoke) to access these methods from C#.