BT

InfoQ Homepage News Xamarin.Essentials Streamlines Cross-Platform Access to Native iOS, Android, and UWP Features

Xamarin.Essentials Streamlines Cross-Platform Access to Native iOS, Android, and UWP Features

Leia em português

Bookmarks

Xamarin.Essentials abstracts native mobile features into a set of cross-platform APIs with the aim of simplifying their use. After a few months in preview, it has been now officially released with a number of enhancements contributed by the community.

Xamarin has long provided a way to use native features offered by the host platform. This comes in the form of bindings that expose the native API in C#. For example, iOS features such as ARKit, accelerometer, and even the Objective-C runtime are available through the Xamarin.iOS framework. This approach allows developers to use native features using the actual iOS, Android, or macOS APIs -- only they can nowdo it without leaving C#.

Xamarin.Essentials pursues a different approach based on a single API that is the same across all supported platforms. This has the advantage that a larger part of your business logic can stay generic. According to Microsoft Xamarin engineer James Montemagno, Xamarin.Essentials is highly optimized and the Xamarin linker will only link the features you actually use and strip out the rest.

Currently, Xamarin.Essentials includes over 30 native features, spanning from connectivity to geolocation, from device information to secure storage, and more.

Many of the APIs included in Xamarin.Essentials attempt to share a similar design. For example, the magnetometer, gyroscope, compass, and others all require you to use the start and stop methods to start or stop to listen for changes on the corresponding sensor, with changes sent back through the ReadingChanged event. Other Essentials APIs follow a more imperative style. For example, to turn the flashlight on or off, securely store a sequence of bytes, or execute a piece of code on the main thread, you just call the corresponding method. The main differences across platforms lies with the different permission systems that each platform adopts and the varying requirements an app must fulfill. Those are thoroughly documented along with each API, though.

Xamarin.Essentials requires Android 4.4 or higher, iOS 10.0 or higher, or UWP 10.0.16299.0 or higher. You can add Xamarin.Essentials to your project using NuGet and reference it from your source files adding using Xamarin.Essentials;. If you already have a Xamarin app and you would like to switch to Xamarin.Essentials, do not miss the transition guide written by Montemagno. Otherwise, a great starting point is the official Xamarin GeoContacts app.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.