OpenFeint with MonoTouch

2019-02-14 23:15发布

I want to use OpenFeint in a MonoTouch project. I have no experience in creating the proper bindings to use a third party Objective-C library with Mono. Reading this article on the Xamarin website did not really help me any further. Has anyone created the bindings necessary to use OpenFeint with MonoTouch or has anyone experience with creating the bindings I need?

2条回答
劫难
2楼-- · 2019-02-15 00:05

In addition to @Jonathan excellent answers...

There are several bindings projects available on github, e.g. from Xamarin, that can give you hints if you're unsure how to convert some Objective-C constructs into C#. Real examples are often very helpful along the theory.

If you ever get blocked in a particular place then do not hesitate to ask specific questions, either here or on the mailing-list.

查看更多
相关推荐>>
3楼-- · 2019-02-15 00:22

It is really easy.

File->New Project->MonoTouch->MonoTouch Binding project

First thing add the Objective-C library (*.a file), it's Build option should automatically say Native Library.

Add all the header files they provide with a Build option of None (this is just for reference to help you write the binding).

Read through the header files and start writing the binding in the ApiDefinitions.cs file:

  • Use [BaseType(typeof(NSObject))] unless their class inherits from something else
  • Use [Export("yourMethod:")] on methods
  • Notice the + and - symbols on methods, + indicates a static method, use [Static] on your end to indicate that
  • If you come across a delegate class (one you need to inherit), add [Model], otherwise it will come out as a sealed class
  • If you need to link other libraries to compile, modify the [LinkWith] attribute in the designer.cs file that shows up underneath the *.a library
  • Enumerations go in the other *.cs file (I forget the name)
  • #define MyConstant 1 - constants like these should go in the class who's header file they're in. Define a new *.cs file with the class as partial. You can also put extra C# code on the class if you wish
  • Map NSTypes to the appropriate C# type: NSString -> string, etc.
  • Feel free to rename the Obj-C types so they aren't as dumb. I've run across random prefixes on every method, member, etc.--remove stuff like that.
  • READ the link you supplied in your question
  • When all is said and done, just reference the new library (don't use any extra build options in project settings, you don't have to use that any more)

In general, it is a good idea to just do it yourself so you are comfortable binding Obj-C libraries like a boss. That is what I would tell a new hire in my department.

查看更多
登录 后发表回答