When faced with the challenge of building a complex offline-capable mobile app, my team turned to Xamarin to revolutionize our approach. Our initial tech stack was built on Ember.js, which worked well in a native shell using Cordova. However, as the project progressed, it became clear that this setup would not be able to handle the demands of supporting Android and iOS devices.

The problem with relying solely on Cordova is its browser-centric approach, which can lead to performance issues and rough edges when building apps for multiple platforms. For our app, we needed to support offline functionality by downloading, processing, and storing user data locally on the device. Unfortunately, this led to slow processing times due to the limitations of JavaScript running in a native web view.

Swift App Development to the Rescue

That's where Xamarin comes in – a powerful framework for building cross-platform apps that leverages the benefits of native development. By using Xamarin with the HybridWebView, we were able to overcome the limitations of Cordova and build a high-performing app that supports offline functionality. The key advantages of using Xamarin include:

  • Native performance: Compiles down to native code, supporting multiple threads for faster processing
  • DRY (Don't Repeat Yourself) principle: Implements most logic in C# with minimal amounts of native code specific to Android or iOS
  • Access to C# features: Leverages the power of C# and its libraries, including Rx.net, async/await, type checking/inference

Writing Swift App Development Code

Once set up, Xamarin provides a seamless interface for executing native code and subscribing to observables from JavaScript. Here's an example of how you can use Xamarin in your own project:

`csharp

public class ExampleServiceObject

{

[WebCallback]

public async Task GetCoord(JToken someArg)

{

// ... native integration / DB look up / etc

return new Point { X = 5, Y = 8 };

}

[WebEvent]

public async Task> OnPositionChanged()

{

// ...

}

}

`

`javascript

import Xamarin from 'my-project/utils/xamarin-interop';

// direct call

var p1Point = Xamarin.call('ExampleServiceObject.GetCoord', "player1");

// subscribe for updates

this._positionSub = Xamarin.subscribe('ExampleServiceObject.OnPositionChanged',

point => {

console.log(point.x, point.y);

}

);

// later on, destroy the subscription when you're done

this._positionSub.destroy();

`

The Results

After making the switch to Xamarin, our app's performance issues disappeared, and we were able to use shared C# code for our new native components. Development and testing became quicker and less frustrating, and we can confidently recommend Xamarin as a go-to choice for building complex mobile web apps that require offline support.