Can an iOS Xcode app install MonoTouch?

I am considering how best to split the effort between teams on a new project. We have a Windows C # application services team and a small iOS Objective-C team. Most likely, sooner or later you will need an Android application.

The domain level / api component on the device, which calls our services and processes synchronization with the local data store, is a logical component for writing in C # and compiling using MonoTouch. The Objective-C command then refers to this component. Is it possible? I read a lot about MonoTouch, referring to C assemblies, but can it work the other way around?

It would be great to hear of any experiences trying to apply this approach, if possible!

Thanks Aaron

+3
source share
1 answer

Although technically possible, there is no easy way to do this today.

The best thing you can do now is run the application with C # and then, if you want, transfer control to your Objective-C code. During C # startup, you can register methods that will be called back with 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);

Note that mycallback must be static (a limitation of static compilation). Then your Objective-C code can consume services, 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);
 }
+2
source

All Articles