Being Serious — Cross-Platform Apps Using Xamarin
Mobile app development is a difficult environment. Businesses, customers, and even developers need a strong foundation of strategy, technology and understanding.
There are plenty of pitfalls along the way — let’s not pretend they don’t exist. Getting products, digital or not, into the hands of others is a journey. There is always something that misses the plan; an obstacle that proves to be a challenge.
Software developers, the folks that write the code to make the app work, have enough worries to deal with in delivering — so the tools and technology they are using shouldn’t be a hindrance. Being an expert in one branch of software development is how developers succeed, and Jacks of all trades may not be the all-knowing oracles that one may assume.
On Apple’s iOS, it mentions none of those top three languages for app development. Java is popular today because Google’s Android and many back-end enterprise systems use this language, from a legacy or familiarity. When you’re in the Microsoft world, you have a steep hill to climb before you get to somewhere you want to be.
Cross-platform is a development strategy that allows it to target multiple platforms from a single base. Traditionally, there are plenty of challenges in trying to create iOS and Android apps that share common functions — code that does the same thing but written more than once in different languages and environments. If you write one function in Java, and write the same function in Swift, unless it is rudimentary (there’s only one way to write 2 + 2), there will be differences. Sometimes these differences are small, others massive due to language features not being available.
Xamarin, developed and supported by Microsoft, helps overcome this problem — for all platforms, developers use one language (C#) and one base code platform (.NET).
It means that the effort to write a particular function (such as an image manipulation function — like an Instagram filter) only needs to be written once and is shared across all platforms. No language differences to complicate matters and saves development time — even more so if you target more than the two mobile platforms!
How It Works
Xamarin is clever in how it can provide one developer platform to work in, yet cross the boundaries between the different device platforms. It supports iOS, Android, Windows 10, macOS, and a few others, all allowing the same developer environment to target them.
Quite the feat, but how does it actually do this? Microsoft split Xamarin into the following three key components: the .NET Framework (DNF), an abstraction layer, and the compiler.
The .NET Framework (DNF)
The DNF provides a whole load of functionality out of the box that covers most of the basic functions a developer would expect, such as file access, mathematics, multi-threading, and so on. This is a large beast, and well documented elsewhere, but essentially it is the platform that someone builds all Xamarin apps upon. It takes nearly 20 years of Microsoft’s development and gives it to Xamarin developers.
Working in cross-platform, a vital concept is an abstraction. For simplicity, this is defining how something must work (a contract) and making it work wherever the definition is needed (an implementation). Developers use this method as a key part of delivering software, and Xamarin also follows this principle.
With all these parts in place — C#, the DNF, abstraction — how does the app get on the target platforms?
This is also the point at which a bunch of platform scenarios need to be resolved, particularly for Apple’s requirements, but Xamarin handles all these transparently.
All these components make up most of the Xamarin ecosystem, and what you get at the end of it is an app that can utilise 99.9% of everything the target platform provides, at speeds equivalent to what you would get using traditional languages and frameworks.
You get a native app, with code sharing, a rich official framework and thousands of fully supported extras to help with the development that bridges the gap between platforms. At Chelsea Apps Factory, we call these Xamarin Native apps.
The Missing Component
So far, we’ve carefully avoided talking about this — the missing piece of the puzzle: an app’s user interface (UI).
No matter what you strive to do in an app, you need to make sure it is both presentable to the end-user and conforms to what you need it to do.
Fortunately, Xamarin provides two offerings that, as a whole, allow the developer the freedom to share the underlying logic code, and still utilise the full UI that each device platform provides.
With the DNF and platform abstraction, Xamarin covers the base platform details. Why not apply these same methodologies to the UI?
Xamarin.Forms is that — a separate product from the core Xamarin platform that allows the UI of different device platforms to be abstracted. Write UI code once for all your devices (a developer’s dream)!
The Forms name came about because Xamarin originally designed it to simplify asking users for data in a form, which using traditional UI development, can be rather tedious. But now, Forms is now in its third version and has significantly outgrown its roots, being able to create powerful, rich and cross-platform UIs that look great, adapt to any kind of screen size, and behave as you’d expect.
Xamarin Native UI
But while Xamarin.Forms sounds amazing, and the answer to everyone’s problems, it, unfortunately, doesn’t quite do everything. Remember that Forms is just an abstraction of the UI, there are things it misses, and certain situations it can’t support without a lot of force.
Xamarin apps need not use Forms, instead, developers can still build apps using each platform’s native UI toolkits, such as storyboarding on iOS and AXML layouts on Android. The difference is that developers get the shared business logic between platforms and the power that the DNF provides (including its excellent multi-threading support).
Advantages are that you get full access to everything the platform’s UI toolkit provides (without abstraction), and it is easier to create unique experiences for each platform. The disadvantages are that it takes a lot longer to develop (over one UI code base), and your app may work differently on different platforms, which may cause more issues in user support.
Let’s Build It!
At CAF we strive to use the tools that deliver the best, most efficient product for our clients. We use Xamarin as our technology of choice to help us do this.
If you’d like to know more about Xamarin and how it could benefit the development of your next digital product come and talk to us over a cup of tea at our Farringdon-based studio or just drop us a line.