简体   繁体   English

如何为Xamarin.iOS创建绑定?

[英]How to create bindings for Xamarin.iOS?

I have an iOS static library(.a and headers file), I want to bind this library to Xamarin.iOS 我有一个iOS静态库(.a和头文件),我想将此库绑定到Xamarin.iOS

I found the binding steps mention on Xamarin site here and in this walkthrough they use the source code of library. 我找到了结合措施提上Xamarin的网站在这里 ,并在此演练中,他们使用的库的源代码。 But I have only .a file and headers file. 但是我只有.a文件和头文件。

Is it possible to bind the static library without the source code. 是否可以在没有源代码的情况下绑定静态库。

You do not need the source code to bind with Objective Sharpie. 您不需要源代码即可与Objective Sharpie绑定。 All you need is the .a library and the headers. 您需要的只是.a库和标头。

Here's an example: 这是一个例子:

sharpie bind -output Binding -sdk iphoneos8.1 \
-scope build/Headers build/Headers/SomeHeader.h \
-c -Ibuild/Headers -arch arm64

Objective Sharpie just output two files: Binding/ApiDefinitions.cs and Binding/StructsAndEnums.cs . 目标Sharpie仅输出两个文件: Binding/ApiDefinitions.csBinding/StructsAndEnums.cs

Then you tweak the bindings as needed and run again. 然后,根据需要调整绑定,然后再次运行。

Once the tweaks are complete, these two files can now be added to a binding project in Xamarin Studio or be passed directly to the touch (iOS) or mac (MacOS X) tools to produce the final binding. 调整完成后,现在可以将这两个文件添加到Xamarin Studio中的绑定项目中,或直接传递给touch (iOS)或mac (MacOS X)工具以生成最终绑定。

Yes this is possible via Objective Sharpie( https://developer.xamarin.com/guides/cross-platform/macios/binding/objective-sharpie/ ) 是的,可以通过Objective Sharpie( https://developer.xamarin.com/guides/cross-platform/macios/binding/objective-sharpie/ )实现

Objective Sharpie uses clang to parse header files which generates quality API definitions. Objective Sharpie使用clang解析头文件,从而生成高质量的API定义。 For the things Objective Sharpie cannot parse/generate, you'll need to normalize yourself. 对于Objective Sharpie无法解析/生成的内容,您需要进行标准化。 These generated files are known as the ApiDefinition.cs and the StructsAndEnums.cs . 这些生成的文件称为ApiDefinition.csStructsAndEnums.cs

To accomplish this, you can use the sharpie bind command. 为此,可以使用sharpie bind命令。

https://developer.xamarin.com/guides/ios/advanced_topics/binding_objective-c/walkthrough/#Using_Objective_Sharpie https://developer.xamarin.com/guides/ios/advanced_topics/binding_objective-c/walkthrough/#Using_Objective_Sharpie

Once you have generated the respective template/scaffolding, you can then pass these items into the bmac / btouch binding tooling which will generate the binding for your platform (Mac/iOS respectfully). 一旦生成了相应的模板/支架,就可以将这些项目传递到bmac / btouch绑定工具中,后者将为您的平台(分别为Mac / iOS)生成绑定。

If you're still running into trouble, there's an advanced example here that should also help: 如果您仍然遇到麻烦,这里有一个高级示例也应该有所帮助:

https://developer.xamarin.com/guides/cross-platform/macios/binding/objective-sharpie/examples/advanced/ https://developer.xamarin.com/guides/cross-platform/macios/binding/objective-sharpie/examples/advanced/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM