Mono + Xcode:如何使用Xamarin Studio在C#中编写一个库,并在Xcode的CocoaTouch项目中使用它? [英] Mono + Xcode: How to author a library in C# using Xamarin Studio, and consume it in a CocoaTouch project within Xcode?

查看:125
本文介绍了Mono + Xcode:如何使用Xamarin Studio在C#中编写一个库,并在Xcode的CocoaTouch项目中使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于最终将移植到Android/Winphone的iOS应用,我希望能够用c#编写一些可重用的库,但是希望使用传统的Obj-C编写iOS UI并引用用c#编写的库从Xcode中提取并从Obj-C中使用.

For an iOS app that will eventually be ported to Android/Winphone, I would love to be able to write some re-usable libraries in c#, but author the iOS UI in traditional Obj-C and reference the library written in c# from Xcode and consume it from Obj-C.

我发现很多文档都在谈论通过绑定的另一种方式(Obj-C-> C#),但是与我的问题无关.另外,在4年前在这里提出了类似的问题,但是生态系统发生了很多变化,信息似乎已过时,答案中的某些链接现在重定向到其他地方:

I've found lots of docs that talk about going the other way via bindings (Obj-C -> C#), but not much pertaining to my question. Also, a similar question was asked 4 years ago here, but a lot has changed in the ecosystem, the info seems out of date, and some of the links in the answers now redirect elsewhere:

那么,这可能吗?如果是这样,那么如何?今天实现它的最佳方法是什么? (或者,这是一个坏主意,应该放弃吗?)

So, is this possible? If so how, and what's the best way to achieve it today? (Or alternately, is this a bad idea and should be abandoned?)

推荐答案

否,当前无法从Objective-C使用C#库.

No, it is not currently possible to consume a C# library from Objective-C.

请注意,通常可以通过一些独创性的方法来完成此操作-唯一的实际要求是该应用程序必须是Xamarin.iOS应用程序,而入口点必须是托管的Main方法.在您的Main方法中,您可以调用本机(C/Objective-C)代码,并在其中拥有所有逻辑.

Note that it is usually possible to do it the other way with some ingenuity - the only real requirement is that the app must be a Xamarin.iOS app and the entry point the managed Main method. In your Main method you can call into native (C/Objective-C) code and have all your logic there.

这篇关于Mono + Xcode:如何使用Xamarin Studio在C#中编写一个库,并在Xcode的CocoaTouch项目中使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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