Monthly Archives: October 2012

Using AirPlay Mirroring to project your iOS UI to an external screen

Not only does MonoTouch allow you to write iOS apps using the ubiquitous and beautiful C# language, but did you know that it also let you control external peripherals?

Whenever a screen gets connected to your device – whether it’s connected through a cable (like TV-out) or through the wireless network (i.e. through AirPlay), an event is published onto the Notification Center. By listening to that event, you can hook that screen up to your app and start putting interesting things there – anything you’d put on your primary UI!

Before we move on, though, it’s important to understand that we as developers actually have no control over the activation of AirPlay Mirroring. Activation is completely up to the user:

Double-tap the home-button, swipe twice to the left and tap the AirPlay button: Image

in the list of available devices, pick your output device and turn the mirroring switch to on:


As the user flicks the Mirroring switch to on, a notification is placed onto the Notification Centre which we can respond to:

CreateWindow then, you ask? It is responsible for hooking up an UIWindow to the external screen and resize it properly to fit its host. Once you have the window in your possession  you can use it like you’d use the default application window:

If your device is already connected to an external screen prior to executing your application, you can easily hook it up in your AppDelegate’s overload of FinishedLoading:

To incrementally test your multi-screen application, you can use the iOS Simulator’s TV-out feature, which is located at Hardware/TV Out:

Please note, however, that turning on the feature tends to shut your app down, why it’s paramount that you have that hook-up in FinishedLoading.

Have fun!

A caveat when using UIAlertViews

Following a common pattern when dealing with UIAlertViews (or InputBoxes, if you want to use the VB lingo (sorry C#:ers – you never had one … ;-) )), I created a UIAlertViewDelegate and a UIAlertView, wrapping them in nice using blocks (you see, all NSObjects implement Dispose to aid the automatic garbage collection by reference counting):

When using the above alert view, however, my app abruptly crashed, tossing out gibberish like “SIGSEGV” near “(wrapper runtime-invoke) object.runtime_invoke_dynamic”. *shivers*

Now, having a feeling that I did something wrong (which is often the case …), I reviewed my recent code additions, set a breakpoint at the target location (the DecryptFile method in this case) and noticed how I just never ended up there. Removing the using statements – i.e. letting the mono garbage collector dispose of the object when it considers it going out of scope – solved the issue:

Hopefully this’ll save you some time when debugging your C# code on iOS. :-)

Book review: Learning MonoTouch – A Hands-On Guide to Building iOS Application with C# and .NET

Having worked with MonoTouch since the first private beta and now actively working as a part of the Xamarin documentation team, Michael Bluestein (blog, twitter, github) is in a great position of authoring this book. Michael was working on the iPhone platform before MonoTouch came around, a fact that shines-through a bit throughout the book, where he can offer us more insights into the underlying platform than previous literature I’ve read.

Starting out with a walk-through of how to get your development environment set up, Mike guides us through creating a basic MonoTouch app. He is good about pointing out what happens beneath the scenes too, giving us insight into what a .XIB file really is, how MonoTouch binds to the controls you lay out in Interface Builder (Xcode) and how to access the underlying fields, if needed be – all in the first chapter of the book!

In chapter 2 - iOS SDK via MonoTouch – Mike gives us the big picture of the iOS SDK, outlining its various components. Beyond that, he also compares the Objective-C and MonoTouch APIs, throwing the reader head-first into the deep-end, something that was left for the last chapter in the previous book I read. Now, this isn’t necessarilly a bad thing – you get hints of how to interoperate with the underlying API – but it would probably make more sense if you had an iOS background. What Mike succeeds in doing, however, is giving you a sense that Objective-C and C# isn’t that different – there are quirks, but there is still a common inheritance.

Chapter 3 walks us through the Model-View-Controller design pattern, which has heavily influenced the iOS (and OSX) SDK API design. Containing a lot of useful information, the chapter is very focused on the available tools – namely Interface Builder (Xcode) – which, unfortunately, has changed substantially since the book was released. Again, though, Mike is good about showing us what happens beneath the veneer, giving us a deeper understanding of how things really work. This chapter contains a fun code example that uses the onboard sensors – making our studies more attached to the real world – and finishes up with explaining how to create your own UIView (like a User-Drawn Control in Windows Forms) and interacting with touch events.

I really liked the book’s fourth chapter - Common iOS Classes – as Mike not only went through a bulk of the available controls (ViewControllers), but also showed how to customise a lot of them to your liking!

Following a chapter with a bulk of the available controls, chapter 5 focuses on tables and navigation – essential bits in any iOS application.

In chapter 6 - Graphics and Animation – we get introduced to Quartz2D and the fundamentals of drawing lines, figures, images and PDF files. As an added bonus, we get a gem in how to attaching a dynamically created PDF document to an outgoing e-mail. The chapter finishes up by introducing Core Animation, which you can get a glimpse of in this video:



Chapter 7 introduces us to Core Location, but also gives us valuable insight into the Significant Location Changes API and the Region Monitoring API, making it highly valuable chapter, even if you’ve read about Core Location before.

After we have learned all about location monitoring, chapter 8 tells us about MapKit, including how to draw annotations (like drop pins) and custom overlays.

Connecting to Web Services is what chapter 9 is all about, doing a good job highlighting the different options available and also containing a nice discussion of when to use the .NET networking APIs contra the CocoaTouch HTTP classes. In the examples, the REST-based API calls are executed against Bing’s search API, making it feel like we are building something real. There are examples of having Bing return both XML (which is parsed with XmlDocument and LINQ-to-XML) and JSON (using System.Json). After walking through REST (being the preferred method whenever possible), we learn about Consuming SOAP-based Web Services using .NET 2.0 client proxies, followed by a section on WCF.

Chapter 10 was another great chapter, offering insights into the Bonjour networking services available on the iOS devices, including GameKit.

In chapter 11, we learn about the various storage APIs we have to our disposal, including SQLite, .NET serialisation against the file system and the application settings APIs.

As the final chapter, iPad Development tells us how to port our iPhone application to the iPad and which extra controls we have available on the bigger screen.


In summary, I found this book to be slightly harder to penetrate than the previous one I read, but on the flip side, I felt that this book contained more information. The book contains some highly valuable gems (ch 4, 7, 9, 10), which alone makes it worthwhile. As such, I can highly recommend it!

Introducing AxCrypt for Mac!

AxCrypt is a leading open source file encryption software for Windows, having more than 2.6m registered users worldwide. Using file-level encryption, AxCrypt is an ideal choice for attaching encrypted documents to your e-mails or for storing files onto your USB drives, for example.

As the Mac OSX is gaining in popularity, it’s getting increasingly more likely that AxCrypt’s users would like to be able to access their encrypted files from the MacBook or iMac too, which is what today’s good news is all about!

Using Mono & MonoMac, we have – in cooperation with Axantum – built an AxCrypt application that runs on your Mac! Being built from the same source as the upcoming 2.x version for Windows, it’s 100% compatible with your existing files, which means that you can start using it today.

The application was developed and tested on Mac OS X Mountain Lion and requires the Mono Runtime to execute. We are looking into bundling the necessary runtime into the app, but unfortunately, at the moment, the current toolset is giving us headaches.

As its older sibling, AxCrypt for Mac is open source.

Download app [Updated May 21st, 2013 to v2.0.2.0 - (read more about the latest version)]

 Scroll to top