MonoTouch / MonoDroid Service Level Incompatibilities?

We started building the Cross platform Android/iOS apps , having previously created it in MonoTouch. We value MonoDroid .

Our applications must consume JSON , and we would like to use ServiceStack . Xamarin has a ServiceStack branch that we use - https://github.com/xamarin/ServiceStack

We would like to have a common project responsible for GETting and POSTing JSON. Xamarin's ServiceStack has different DLLs for Android and iOS . How do we have a single project and use ServiceStack for our JSON?

Are we open to other JSON sharing options?

+4
source share
2 answers

In general, a managed * .dll compiled for MonoTouch that does not depend on specific MonoTouch types is compatible with Mono projects for Android.

ServiceStack is a great example of this. I personally used it for several projects as part of the Xamarin mobile app offerings.

Generally, I tend to encapsulate all calls to my web services using an incomplete class with asynchronous methods like FooProjectRestClient . And then, if there ever will be some kind of segmentation that needs to happen, it can happen in a general class using #if defs.

+4
source

The reason MonoTouch and Mono for specific Android libraries often occurs due to the existing (smaller, more customized Silverlight) profile (for example, everything that depends on the new FX4.0 features should be cut). They often represent the same code compiled with SILVERLIGHT (or MONOTOUCH , MONODROID ).

The reason for MonoTouch's specific librairies is only because its environment (iOS devices) does not allow JIT'ing. Thus, there is no generation code (for example, System.Reflection.Emit ) or dynamic (down) loading code ... However, it is often possible to provide (less efficient) workarounds or skip several functions and save a special version of the library for MonoTouch.

Now back to creating a single shared assembly / project. The special MonoTouch assembly (usually the same code compiled with MONOTOUCH ) is still a reliable .NET assembly and can often be used in Mono for Android, Mono or .NET (recompiled once, even with MONOTOUCH ). This is ultimately not optimal, but it is something you can try.

Another of them has the same projects (for example, MyLib), in several solutions (for example, MonoTouchApp, M4AndroidApp) and uses special configurations (like iPhone | Debug one) to set different definitions (for example, MONOTOUCH on iPhone * | *). This may allow you to maintain a better implementation of functions on all platforms (for example, if the same function is implemented differently).

I would try later (config), and then split up the special MonoTouch assembly and finally (if it really doesn't work) looking for other alternatives.

+3
source

Source: https://habr.com/ru/post/1400452/


All Articles