OpenFeint with MonoTouch

I want to use OpenFeint on a MonoTouch project. I have no experience in creating the correct bindings for using the third party Objective-C library with Mono. Reading this article on the Xamarin website didn't really help me further. Has anyone created the bindings I need to use OpenFeint with MonoTouch, or does anyone have experience creating the bindings I need?

+3


source to share


2 answers


It's very simple.

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

First add the Objective-C library (* .a file), it should automatically point to <String> Native Library

.

Add all the header files they provide with the Build option None

(this is for reference only, to help you write the binding).



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

  • Use [BaseType(typeof(NSObject))]

    if their class does not inherit something else
  • Use [Export("yourMethod:")]

    for methods
  • Note the + and - symbols on methods, + indicates a static method, use [Static]

    at the end to indicate that
  • If you come across a delegate class (the one you need to inherit) add [Model]

    , otherwise it will exit as a private class
  • If you need to link other libraries for compilation, change the [LinkWith] attribute in the designer.cs file that appears under the * .a library
  • The enumerations go in another * .cs file (I forgot the name)
  • #define MyConstant 1

    - such constants must be in the class, in which header file they are located. Define a new * .cs file with the class as partial. You can also add an additional C # class to the class if you like
  • Map NSTypes to corresponding C # type: NSString -> string, etc.
  • Remember to rename the Obj-C types so they are not so dumb. I came across random prefixes for every method, member, etc. - remove such things.
  • PLEASE READ the link provided in your question.
  • When all is said and done, just refer to the new library (don't use additional build options in project settings, you don't need to do this anymore)

In general, it's a good idea to just do it yourself, so you're more comfortable linking the Obj-C libraries like a boss. This is what I will tell you about the new rental in my department.

+3


source


In addition to @ Jonathan's great answers ...

There are several bindings projects available on github for example. from Xamarin , which can give you hints if you don't know how to convert some Objective-C constructors to C #. Real-world examples are often very useful in theory.



If you ever get blocked at a specific location, feel free to ask specific questions, either here or on the mailing list .

+1


source







All Articles