开发者

Can an iOS XCode application reference MonoTouch assemblies?

I'm considering how to best divide the effort between the teams for a new proj开发者_如何学Cect. We've a Windows C# application services team and a smaller iOS Objective-C team. It's also likely sooner or later an Android application will be required.

A domain layer/api assembly on the device that calls our services and handles synchronising with a local data store is a logical component to write in C# and compile with MonoTouch. Then the Objective-C team references this component. Is that possible? I've read plenty on MonoTouch referencing C assemblies, but can it work the other way around?

It'd be fantastic to hear of any experiences trying this approach out if it is possible!

Thanks Aaron


Although technically possible, there is no easy way of doing so today.

The best you can do for now is to launch the application from C#, and then, if you want, transfer control to your Objective-C code. During the C# launch, you can register methods to be called back by the Objective-C code using P/Invoke to call something like:

delegate void some_callback_t (int parameter1, int parameter2);

[DllImport ("__Internal")]
void SetCallback (some_callback_t callback);

static void mycallback (int parameter1, int parameter2)
{
    // Here goes your C# logic to be called by C
}

Then you call:

SetCallback (mycallback);

Notice that the mycallback has to be a static method (a limitation of static compilation). Then your Objective-C code can consume services by implementing something like:

 typedef (*callback_t) (int p1, int p2);
 callback_t callback;
 void SetCallback (callback_t cb)
 {
     callback = cb;
 }

 void InvokeCSharp ()
 {
     callback (1, 2);
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜