How to create an iOS binding library for .NET MAUI

Wei Wen 1,096 Reputation points

I have a .NET MAUI app which needs to use native iOS and Android libraries. I created the Android binding library without any issue. When trying to create the iOS binding library, I found that the only reasonable option is to choose "Binding Library" under "Unified API". However, after the binding library project is created, I found that the project structure is a bit different than Xamarin.Forms: There is no Frameworks folder.

The bigger problem is that there is no StructsAndEnums.cs file, only Structs.cs file. But when I used objective sharpie to create bindings, it created two files, ApiDefinition.cs and StructsAndEnums.cs. I can copy the content of the ApiDefinition.cs into the one in the binding library project, but I cannot copy the content of StructsAndEnums.cs into Structs.cs in the binding library project. I think there is a reason it is called Structs.cs, not StructsAndEnums.cs. But there are enum definitions in the StructsAndEnums.cs created in sharpie that are used in ApiDefinition.cs. So I do need StructsAndEnums.cs. I tried to rename Structs.cs to StructsAndEnums.cs and copy the content into it. Still it said the enums didn't exist in the current context.

I use Visual Studio 2022 v17.4 Preview version.

Any help is greatly appreciated!

A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,154 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Wei Wen 1,096 Reputation points

    I was able to solve the problem by changing the sbyte type to string type. Sbyte was set as input parameter's type when objective sharpie was trying to generate ApiDefinition.cs file.

  2. John Begley 0 Reputation points

    Was this successful in the end? I am also doing this but I don't think I can even get as far as you did as I can't even compile. My problem is that BaseType[Attribute] could not be found in the ApiDefinition. This is defined in Xamarin.iOS, but does not seem to be available in .NET7. Even when I create a Bindings project under Unified API (As you mention above) It shows example API code with this attribute.

    I feel like I'm missing something here, or am looking for the answer to the wrong question or something. I can't seem to find anyone who has created .NET to iOS bindings which will work in MAUI and not tied to Xamarin.iOS.