Don of the Day

Don of the Day


Adventures in software development with Xamarin and the Web

Software developer, building things with code in sunny Scottsdale, AZ.

Share


Twitter


Developing an iOS App With Xamarin

Don FitzsimmonsDon Fitzsimmons

For the past few weeks, I've been building an app in my spare time. This app, it's for local gym and it's really just a highly customized HIIT/Tabata timer used to run group workouts. It has to run on iOS. Now, I'm not an iOS developer. In the past, I did write a Windows Phone app, but nothing for iOS. This would begin my adventure into the mainstream app world and I had plenty of options to choose from to create the app. You already know that I'm using Xamarin to build the app because of the post title, but I did a ton of research before deciding to commit to Xamarin for this project.

Many Options

There's not shortage of options if you're a developer wanting to build mobile software, you just have to choose based on your abilities and the requirements of your app. Really, there's no easy answer. From drag-and-drop app builders to writing native code; it's a broad spectrum.

Going Native

Get a Mac, download Xcode learn Objective-C, or, better yet, Swift and start learning the API's. Many will tell you that this is ultimately the best way to write apps. You're using the platform tools and developing the app the way Apple intended. So why not just go native?

The amount of time it takes to just learn the API's for a mobile platform alone is daunting (think UIKit, Foundation, etc). On top of that, you've got to learn all of the UI paradigms (Autolayout, ViewController, etc). If I'm going to do all of that learning, picking up a new language along the way is going make for a really steep learning curve and a long, bumpy road.

I do agree that ultimately, I would be better off taking the native path, but I also have a product to deliver, so I need to get something done in a relatively short amount of time. Not to mention, if you need your app to run on Android too, you're stuck learning yet another language and platform. Maybe there's another option.

Ionic Framework (Cordova)

Another path to app development is to use Apache Cordova and web tools to build an app that's really a web app packaged in a mobile browser. This used to be a less desirable way to create an app because it wouldn't look like a "real" app. And, performance in mobile browsers was problematic as well. Choppy frame rates, laggy transitions, etc.

Things have changed both with mobile browsers and the tools for creating Cordova apps. I discovered the Ionic Framework and found that it is possible to write apps using HTML, Javascript, Angular and Cordova and theses apps look and feel like native apps. The work that the Ionic team has done is truly impressive.

Because I already know how to use the tools, (web development tools, that is) I wouldn't have to learn the native API's at all. In fact, playing around with Ionic, I had a basic prototype of my app up and running in a few hours. And it looked like a native iOS app and performed like one. I was impressed.

There's is a catch. There's always a catch. One problem that I have with Ionic is that it's currently in a state of flux. There's Ionic 1, which is based on Angular 1. And now, there's Ionic 2, which is based on Angular 2. I don't want to start learning a framework that's essentially going to be deprecated (version 1) and version 2 of both Ionic and Angular are beta. This means lots of change and little documentation beyond simple stuff.

Another problem with the Cordova approach to app development that I have found, the Cordova plugins are not well maintained. Some are, but it's a bit of a crap shoot. The reason I did not end up using Ionic is not the fault of Ionic at all, but the lack of a reliable audio plugin with deep integration with Apple's AVAudioPlayer and AVAudioSession.

Ionic is promising and I will certainly revisit it again in the future. Hopefully they'll be beyond beta by then and things will be more stable. I'm not sure if the Cordova plugin situation will ever be reliable, but I also understand that plugins are tracking a moving target and a single plugin to cover functionality in every mobile platform is a serious challenge.

Xamarin

I'm familiar with the concept of Xamarin and I've flirted with using it over the years, but never quite had a real need. For this project I'm working on, it seemed like the perfect fit. I could write my app using C#, my language of choice (been using it for about 10 years), my app will run as a truly native app and I'll be using familiar tools (Xamarin Studio has many similarities to Visual Studio). Not to mention, the kind folks at Xamarin gave me a complimentary professional license so cost is not an issue.

One thing to understand about Xamarin: you will be writing 2 user interfaces if you plan to target iOS and Android. Sure, you can architect your code to share as much functionality as possible (PCL's FTW) but you will also have to learn the native API's. So there's no time savings there. Of course, you could try Xamarin.Forms which aims at allowing you to write one UI for both platforms, but there are many limitations and frankly, I haven't tried it.

Also, I want to learn the native API for iOS. The real advantage to using Xamarin is that while I am dealing with the learning curve for the native API's, I'm not dealing with the additional overhead of learning a new language on top of that because I get to use C#. Also, I do plan to learn Swift in the near future and having gained the experience of using the iOS API's with C# and Xamarin, I can focus on learning Swift on my next app. Win, win.

What It's Like - Xamarin

So far, my development experience has been really good. I'm using Xamarin Studio exclusively because my little MacBook Pro isn't powerful enough to run Parallels and Visual Studio. But, honestly, I don't mind it. It's familiar with many of the same conventions of Visual Studio. It's not nearly as powerful, but it's enough to get the job done...mostly.

The Xamarin Studio designer is the weak spot in my experience. It's slow, and the autolayout functionality is not so great. I've just started using Xcode to do my design work and then I use the Xamarin Studio designer to wire up my views to my view controllers. It's not ideal, but it works.

Overall, I'm able to write my app and nothing about Xamarin has gotten in my way or limited me so far. I love being able to use C#, the familiarity really takes the edge off of learning this new platform (iOS). If you can afford it, Xamarin is really nice and now that Microsoft has acquired Xamarin, I think it will only get better (and maybe more affordable).

What It's Like - iOS Development

I can only compare my iOS development experience to my Windows and Windows Phone development experience. The first thing that stands out the most, the design-time experience is terrible. The autolayout system is a pain in the ass and Xcode is about 5 years behind Visual Studio. I used to complain about XAML and how it could be frustrating, but after using Xcode to design layouts, I long for XAML and Expression Blend. It's hard to believe that with the emphasis on aesthetics on iOS, designing beautiful interfaces is such a difficult task.

My app isn't using anything special in terms of device hardware. As I mentioned before, I am using the audio features of the device. Namely, my app is a timer so there are periodic voice prompts as the timer ticks away. The app is run while iTunes plays in the background so my voice prompts have to "duck" the background audio. Turns out, Apple has built this ducking feature into the audio API and it works well once you get over some of the strangeness of the the way it works.

Developing for iOS is a very different experience than working with Windows and XAML. It feels so much more primitive and clunky. Especially the storyboard. But, once you get your brain around some of the concepts, it's not hard to find a rhythm and start producing. I plan to invest a lot more time into iOS, so I'm willing to deal with it.

The Future

I have decided that this current app I'm working is a great way to get myself acquainted with iOS while using a familiar language, but my next app, one that I'll write for myself and sell in the App Store, I'll be using Swift and going native all the way. Although Xamarin provides the tools to use my existing skills, I feel it's time to push myself a little further and learn a new language. We'll see how that goes.

Conclusion

These are the frameworks and tools I chose to experiment with and use, but there are other tools out there too. Like, NativeScript and React Native that look promising too. Because I already know C# and have access to Xamarin, that's the route I went and it's paid off for me. I do plan to learn Swift soon and write a complete iOS app. More to come on that.

Software developer, building things with code in sunny Scottsdale, AZ.

Comments