These are the steps I performed and got it working without any issue:
- I created the following folder structure:
App (.NET 8.0, MAUI)
│ App.csproj
│ ...
App.Framework (newly created structure)
└───FAT
└───Frameworks
App.Binding (iOS/MacCatalyst Binding Library)
│ ApiDefinition.cs
│ App.Binding.csproj
│ StructsAndEnums.cs
- Copied the .framework into the
App.Framework/Frameworks
AND theApp.Framework/FAT
directory - Created a FAT framework by using the following command:
lipo -create -output FAT/[Name].framework/[Name] Frameworks/[Name].framework/[Name]
HINT: As long as the architectures are different, you can add multiple architectures into a FAT framework - Created
ApiDefinition.cs
andStructsAndEnums.cs
by using the following command:sharpie bind --sdk=iphoneos16.2 --output="ApiDefinition" --namespace="App.Binding" --scope="FAT/[Name].framework/Headers/" "FAT/[Name].framework/Headers/[Name].h"
NOTE: You might need to fix the path to absolute paths, if your framework contains multiple header files and if you are using Apple frameworks you might need to run this command with elevated permissions (sudo), check the sdk you want to use - Check the generated files in
App.Framework/ApiDefinitions/
and move the parts you need to theApp.Binding/ApiDefinition.cs
andApp.Binding/StructsAndEnums.cs
- Remove
[Verify]
attribute after you checked those parts of the definitions - Add the following snippet to your
App.Bindings/App.Binding.csproj
:
<ItemGroup>
<NativeReference Include="..\App.Framework\FAT\[Name].framework">
<Kind>Framework</Kind>
<Frameworks>Foundation UIKit [Name]</Frameworks>
<LinkerFlags>-L "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/" -L "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos" -Wl,-rpath -Wl,@executable_path/Frameworks</LinkerFlags>
</NativeReference>
</ItemGroup>
NOTE: You might need to modify the path to the target you are building for and modify the list of the frameworks in use
8. Link the project as ProjectReference
in your App.csproj
, e. g. without conditions like this:
<ItemGroup>
<ProjectReference Include="..\App.Binding\App.Binding.csproj"/>
</ItemGroup>
NOTE: Some IDEs require you to build the Binding by hand and unload the project in order to get the code completion / lookups working.
---
I hope I did not forget anything and hopefully it will get you started. If you need any further information, just let me know!
BR, Niko