In spite of the time we all spend on our computers these days, mobile app usage is overtaking the desktop: 51% of total time spent online in the US is on a mobile device. With this trend comes a challenge: how can your developers come up to speed fast enough to develop cross-platform mobile apps, including all the types of devices in the hands—or on the wrists—of your users?

Enter Xamarin—a free, open source framework from Microsoft which can revolutionize your cross-platform development by shaving time and cost to build and maintain mobile apps.

Previously, we’ve explained the advantages of using Xamarin for mobile application development, including:

  • Xamarin makes real native apps
  • Developers can share up to 95% of code across platforms
  • Your team can be more productive using the .NET ecosystem
  • The Xamarin Forms framework uses the native user interface controls for each mobile platform. This means the applications have the expected look and feel across all mobile devices.

A Cross-Platform UI With Xamarin.Forms

When tackling a client mobile app a few years ago, time to market was essential. We briefly evaluated the idea of writing the app natively in Java for Android and Swift for iOS. What we quickly realized is we’d be doing twice the work—both now and over time as we enhanced the app.

Instead we turned to Xamarin, and more specifically, Xamarin.Forms. This cross-platform framework allowed us to write the user interface code once and compile it natively for each platform. The result is an app that looks and functions the same on both platforms. We shaved tons of time off the schedule and saved our client hundreds of thousands of dollars.

Xamarin Essentials Reduces Code Even Further

Xamarin.Forms does an excellent job translating all the common UI components into their native counterparts for each platform. But what if your application needs to access some device specific features such as the battery, SMS messaging, compass or gyroscope?

Xamarin provides 100% access to each platform, but due to different APIs, the code needs to be written independently for each platform. This is a powerful feature of Xamarin, but reduces the amount of code that can be shared. But there is a solution: Xamarin.Essentials.

Xamarin.Essentials provides developers with a unified, cross-platform approach to working with operating system-specific features. This means instead of learning each platform-specific API, developers can learn one framework, write the code in C# once, and share that code across mobile platforms.

To illustrate the difference, consider something that seems like it should be simple: turning on or off the device’s flashlight. Here’s how many lines of Xamarin code required on each platform:

  • iOS: 53
  • Android: 106

With Xamarin.Essentials, it’s one line of code:
Flashlight.TurnOnAsync();
The Microsoft engineers have handled all the heavy lifting for us. They’ve provided the platform-specific implementations, completely shielding us from all of the messiness.

Note that if we wanted to, we could continue to write platform-specific code in C# using Xamarin. But for common operations, we aren’t forced to write and maintain our own code.

What about something a little more complicated, like sending an SMS message? The code would look something like this:
var message = new SmsMessage(messageText, recipients);
await Sms.ComposeAsync(message);

That’s a heck of a lot better than the hundreds of lines of code required to implement this for both iOS and Android.

Conclusion

Xamarin.Forms is a UI framework that allows developers to create user interfaces from a single shared codebase, resulting in an app that looks and feels that same on each platform, while utilizing the native user interface controls on each platform. This lets your team share up to 90% of the code across platforms.

Xamarin.Essentials allows your teams to be even more productive when your application requires platform-specific features. The code is simple, shared, cross platform compatible and written in C#. Adding Xamarin.Essentials into the mix lets your team share up to 98% of the code across platforms.

Take a look at the Xamarin.Essentials documentation and see how easy it is to add some cool features to your mobile applications.

To learn more about creating cross-platform mobile apps, watch the webinar we presented on this topic, which includes live Q&A with our attendees.

Share This Article