Mobile development 3/3 – different approaches
In the previous two articles, we took the helicopter view on things and then gazed at a responsive and a hybrid approach to build our poker planning app [1]. In this episode we’ll look deeper into the fourth option, namely the promising world of cross platform development using Xamarin. You can download the example code in the final section of the episode.
Xamarin solution
Total freedom and control of the final solution would be to maintain separate code bases for each mobile platform, but as commented on earlier, we would then have to develop using very different strategies, platforms and tools. The cost of doing so could soon exceed the gains. Xamarin however, offers a unified approach to app development with several benefits and few limitations.
The benefits are manifold and includes:
You only need to master one language C#/.NET – but, you can also choose to use F#, or mix the two
- For large parts of the code-base you only need to master one platform (.NET)
- For more specialized, platform specific development, you can still get a high degree of portable code using e.g. Xamarin.Forms
- You get the 100% native app feel, and the possibilities that goes along with it
- Language facilities like full support for lambda’s and async code
Xamarin supports all major platforms at the market (Android, Mac OS, iOS, Windows Mobile, UWP), but still, there are of course limitations with respect to the all mighty Mac. You still need a Mac for compilation, either locally or using one of the costly hosted solutions in the cloud (examples are MacInCloud and MacStadium). One can only speculate, when Apple realises this very unwise decision leads to a dead end. Opening up the world is the winning strategy – not protectionism.
Xamarin is still a relatively young product, and as such suffers from some child diseases. This includes missing implementations in Xamarin.Forms (e.g. why do I have to roll my own gesture recognizers?) and the necessary dependencies on the myriad of iOS and Android platform distributions is a source of constant pain.
You’ll need to make sure you have the same implementations of Xamarin and Mono (the .NET cross-platform implementation base) installed on your Mac and on your pc (installed by e.g. Xamarin Studio). Also, the installed version of the Java.SDK, Android.SDK and supporting libraries is important on the Android side of things. And only if you have a Visual Studio Enterprise license can you remote debug your iOS app using a Windows simulator (Xamarin: But why?).
The poker planning card app was developed with Xamarin using Visual Studio, but a more viable option perhaps, is to use the more mature Xamarin Studio.
Implementation details
The Visual Studio solution is structured around a portable project containing most of the code base. Xamarin distinguishes between a portable and a shared project, which essentially is the difference between using run- and compile-time platform differentiation. If you do a shared project, you’ll have to throw in compile-time directives for each piece of platform specific code.
Figure 3: Poker Planning solution
Notice, we didn’t bother implementing UWP or Windows Phone versions of the app, though this is certainly another benefit from using Xamarin. The market shares for Windows Mobile seems to vanish very quickly.
Although there are platform specific libraries for doing portable graphics stuff, in this solution we’re using Xamarin.Forms only. Xamarin.Forms aims at packaging most of the trivial platform differences for a lot of standard controls, like text labels, buttons, dropdowns and so on. If you encounter limitations or prefer to roll your own, this is possible using platform specific renderers (still using .NET). An example of a custom renderer, is the poker planning app RoundedFrameViewRenderer, which on Android devices draws a solid 2D representation of the card boundary and on iOS devices draws a drop shadow version.
Figure 4: Card app with Android and iOS using Xamarin.Forms
Other examples of customizations are gesture recognizers (swipe handling), but apart from the drawing and gesture stuff, the poker planning app is completely portable with Xamarin.Forms code.
Conclusion
This concludes our brief tour-de-force in the major direction in mobile app development. Feel free to download the solution .ZIP file and experiment for yourself.
pokerplanning (973,75 kb)
References
[1] PLANNING POKER ® is a registered trademark of Mountain Goat Software, LLC. Sequence of values is (C) Mountain Goat Software, LLC
Would you like our help delivering your next mobile app using Xamarin?
Morten Hoffmann
CEO
T: (+45) 3095 6416 E: mhs@strongminds.dk