使用 MonoTouch 的 OpenFeint [英] OpenFeint with MonoTouch

查看:19
本文介绍了使用 MonoTouch 的 OpenFeint的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 MonoTouch 项目中使用 OpenFeint.我没有创建适当的绑定以使用带有 Mono 的第三方 Objective-C 库的经验.在 Xamarin 网站上阅读这篇文章并没有真正帮助我.有没有人创建了将 OpenFeint 与 MonoTouch 结合使用所需的绑定,或者有没有人创建过我需要的绑定?

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?

推荐答案

真的很简单.

File->New Project->MonoTouch->MonoTouch 绑定项目

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

首先添加Objective-C库(*.a文件),它的构建选项应该自动显示Native Library.

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

添加他们提供的所有头文件,并带有None的Build选项(这只是为了帮助您编写绑定的参考).

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

通读头文件并开始在 ApiDefinitions.cs 文件中写入绑定:

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

  • 使用 [BaseType(typeof(NSObject))] 除非它们的类继承自其他东西
  • 在方法上使用 [Export("yourMethod:")]
  • 注意方法上的 + 和 - 符号,+ 表示静态方法,在您的末尾使用 [Static] 表示
  • 如果遇到委托类(需要继承的类),添加[Model],否则会以密封类的形式出来
  • 如果您需要链接其他库进行编译,请修改显示在 *.a 库下方的 Designer.cs 文件中的 [LinkWith] 属性
  • 枚举进入另一个 *.cs 文件(我忘记名字了)
  • #define MyConstant 1 - 像这样的常量应该放在它们所在的类的头文件中.定义一个新的 *.cs 文件,该类为部分类.如果您愿意,您还可以在类中添加额外的 C# 代码
  • 将 NSTypes 映射到适当的 C# 类型:NSString -> 字符串等
  • 随意重命名 Obj-C 类型,这样它们就不会那么笨了.我在每个方法、成员等上都遇到过随机前缀——删除类似的东西.
  • 阅读您在问题中提供的链接
  • 当一切都完成后,只需引用新库(不要在项目设置中使用任何额外的构建选项,您不必再使用它)
  • 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)

一般来说,自己动手是个好主意,这样您就可以像老板一样轻松地绑定 Obj-C 库.这就是我会告诉我部门的新员工的话.

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.

这篇关于使用 MonoTouch 的 OpenFeint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆