MonoTouch:从 Obj-C 到 MonoTouch [英] MonoTouch: talking from Obj-C to MonoTouch

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

问题描述

我正在尝试从现有的 Objective C 项目调用 MonoTouch 程序集.我找到了这篇文章:

I'm trying to call into a MonoTouch assembly from an existing Objective C project. I found this article:

http://www.guidebee.biz/forum/redirect.php?fid=16&tid=176&goto=nextoldset

在那里它很好地描述了步骤但是当我尝试在 XCode 中构建项目时,我收到以下错误:

In there it pretty much describes the steps very well however when I try to build the project in XCode I get the following error:

错误:没有指定名称或路径的 SDK '/Developer/MonoTouch/SDKs/MonoTouch.iphonesimulator.sdk'

error: There is no SDK with specified name or path '/Developer/MonoTouch/SDKs/MonoTouch.iphonesimulator.sdk'

所以,要清楚:

  1. 我添加了架构附加 SDK 的正确路径
  2. 物理检查路径是否正确
  3. 我正在针对 iOS 4.2 的最新 SDK(无论如何我都有)进行构建

我被难住了.这是 XCode 没有找到正确的 SDK 路径或更深层次的问题吗?令人担忧的是,我注意到文章中引用的 URL ( http://monotouch.net/Documentation/XCode) 现在丢失了 - Novell MonoTouch 是否出于某种原因故意删除了它?

I am stumped. Is this a problem with XCode not finding the correct path to the SDK or something deeper? Worryingly I noticed that the URL referenced in the article ( http://monotouch.net/Documentation/XCode ) is now missing - so has Novell MonoTouch deliberately removed this for some reason?

好吧,我完全被难住了 - 我也无法使用选择器将 Mono 转换为 Obj-C 代码.所以作为最后的尝试,我发布了代码:

Well I'm completely stumped - I cannot cal from Mono into Obj-C code using Selectors either. So as a last ditch attempt I'm posting the code:

@implementation MonoWrapper
- (id)init {
    self = [super init];
    
    if (self) {
        NSBundle *main = [NSBundle mainBundle];
        NSString *path = [main bundlePath];
        const char *c_path = [path UTF8String];
        
        [main autorelease]; 
        [path autorelease];
        
        chdir (c_path);
        setenv ("MONO_PATH", c_path, 1);
        setenv ("MONO_XMLSERIALIZER_THS", "no", 1);
        setenv ("DYLD_BIND_AT_LAUNCH", "1", 1);
        setenv ("MONO_REFLECTION_SERIALIZER", "yes", 1);

        _domain = mono_jit_init_version ("MonoTouch", "v2.0.50727");
        MonoAssembly *assembly = mono_assembly_open("PhoneGap.dll", NULL);
        MonoImage *image = mono_assembly_get_image(assembly);
        MonoClass *class = mono_class_from_name(image, "PhoneGap", "PhoneGap");
        MonoMethodDesc *methodDesc = mono_method_desc_new("PhoneGap.PhoneGap:getInt", TRUE);
        _callbackMethod = mono_method_desc_search_in_class(methodDesc, class);
        
        /* allocate memory for the object */
        _instance = mono_object_new (_domain, class);
        /* execute the default argument-less constructor */
        mono_runtime_object_init (_instance);   
        
    }
    // Done
    return self;
}

- (void)DoSomething {
    int jim = 0;
} 

- (int)multiplyA:(int)a {
    void *params[] = { self, @selector(DoSomething), &a };
    MonoObject *result = mono_runtime_invoke(_callbackMethod, _instance, params, NULL);
    int n = *(int*)mono_object_unbox (result);
    return n;
}
@end

在单声道中:

using System;
using MonoTouch.ObjCRuntime;  

namespace PhoneGap
{
    public class PhoneGap
    {
        public PhoneGap ()
        {
        }

        public int getInt(IntPtr instance, IntPtr sel, int val) {
            
            
            Messaging.void_objc_msgSend (instance, sel);
            return val * 2;
        }
    }
}

谁能告诉我如何在 Mono 中获取 Target 实例句柄以及如何获取 Selector?

Can anyone tell me how to get the Target instance handle in Mono and how to get the Selector?

推荐答案

MonoTouch 过去在我们拥有自己的调试器之前就包含了支持.我们已经弃用了这种支持,因为我们现在拥有一个完全成熟的调试器.您尝试执行的操作虽然在技术上可行,但不受支持的工作流程.如果您想继续沿着这条路走下去,我建议将-keeptemp"标志与 MonoTouch 结合使用-v -v -v",这不会删除我们在编译项目时生成的临时文件.

MonoTouch historically included support before we had our own debugger. We have since deprecated this support as we now have a fully fledged debugger. What you are trying to do, while technically possible is not a supported workflow. If you wish to continue down this path, I suggest using the "-keeptemp" flag to MonoTouch combined with "-v -v -v" which will not delete the temporary files we generate when compiling the project.

利用这些信息,你可以提取 main.m 模板,理论上可以弄清楚如何调用 arm-darwin-mono 来交叉编译自己.

Using this information you can extract the main.m template, and could theoretically figure out how to invoke arm-darwin-mono to cross compile yourself.

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

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