Xamain.iOS – Mapping & My Location

So, you’ve created your MKMapView in your view controller and instantiated a CLLocationManager which you’ve called RequestWhenInUseAuthorization() on. Everything tells you that this should be enough so that when the Map loads and requests the current location iOS will prompt the user whether they want to allow the device to share it’s location – but the prompt is never displayed and neither is the location.

I watched a Xamarin University course on iOS Mapping (IOS 230) and when I followed along with the exercise using a new project (not the one provided in the course materials) the location was still not displayed. But, when I ran the Completed project in the course materials I was prompted to allow location sharing and when I clicked ‘Allow’ the location was displayed. Looking at the code it did not seem to be any different from mine (but of course it had to be).

I finally found the missing element – it was a missing property in the Info.plist file. The Xamarin course materials had it but it was not mentioned during the course itself.

The good news is that it is super simple to fix this:

  • Open Xamarin Studio
  • Open Info.plist
  • Using the tabs at the bottom of the window – select ‘Source’
  • Click the ‘Add new entry’ text at the bottom of the table and add a new String property as follows:
    • Property: NSLocationWhenInUseUsageDescription
    • Value: Show map location
  • Save the file

That’s it – run the app again and (as if my magic) you will be prompted to allow access to your location and (if you click Allow) your location will be displayed.

You can download the (very basic) solution used above by clicking here.

Note that the solution was created using Xamarin Studio 5.9.5 (build 9) and Xamarin.iOS (Business Edition)

Getting Started with Xamarin – a Pet Project

In previous posts I have mentioned that 2014 will be my ‘Year of the Mobile‘ and that Xamarin (which will allow me to develop for Android, iOS and Windows Phone using C#) will be my weapon of choice.

As with all undertakings such as this I needed a few pet projects to work on, something that more closely resembles a real world application than some contrived examples that you find in some books and web tutorials (that’s not to say that all book and web tutorials are created equally).

I already have my FillLPG application, written in Java, which I am moving to C# via Xamarin but I wanted something that integrated with the standard phone functionality, e.g. phone calls, SMS. I also wanted it to be something that I could make use of myself – scratching my own itch if you will.

I’ve had a number of ideas but you need to walk before you can run so I’ve opted for an SMS Scheduler app. Yes, I know that this has already been done both as an integrated feature in full blown messaging applications and standalone utility apps (which is what mine will be) but that’s no reason not to use it as an learning exercise. The requirements are such that it will provide a number of opportunities for investigation into operations such as:

  • Contact Selection (taking into account some contacts may have multiple phone numbers)
  • Date/Time Pickers
  • Data storage (probably file based – SQLite is a bit heavy weight for this in my opinion)
  • Scheduling of the SMS ‘jobs’
  • Sending of the SMS itself
  • Logging and Notifications

As with previous ‘tutorials’ I’ll provide full source code at each step and the final project will also be on GitHub.

As I am predominantly an Android user I will be developing for that platform first but with a mind to sharing as much code as is practical.

2014 – The Year of the Mobile?

I’ve always said that when it comes to software development, you have to “pick your fights” – it’s just not possible to keep up with the ever-changing technologies. We only have so much time to spend learning new technologies and techniques so it is important to carefully consider what to focus on and what to let pass us by.

When it comes to Mobile development I have released a simple, native, Android app which was written using my somewhat rusty Java skills. At the time of writing the app is installed on around 5000 devices (if Google Play is to be believed). Since it’s original release I have addressed bugs and added a few requested features but I found it to be a bit of a struggle due to Java not being my main development language – but I simply don’t have time to bring my Java skills up to the required level. As for iPhone/iPad development I have joked that “I don’t have enough time left in my life to learn Objective C “.

So when I heard about a product which will allow developers to create native applications for Android & iOS (and Windows Phone) using C# (my language of choice) I was naturally intrigued.

The Xamarin ‘framework’ provides a set of bindings which sit above the Android and iOS APIs  allowing C# code to be compiled into native applications for the target platform. Moreover, it is possible to share large chunks of code between platforms thus reducing maintenance and duplication.

I’m currently in the process of completely rewriting the FillLPG application using Xamarin and C# with a view to reusing as much code as possible in order to ease the process of developing a version for iOS. It’s not been an easy process by any means – every new technology has it’s learning curve and fair share of bugs and issues, but because I’m using C# – indeed I’m also using Visual Studio 2013 – at least I’m not starting from zero.

The process of rewriting the FillLPG application has taught me a lot but as the old adage goes ‘you don’t know what you don’t know’ so I’ve also enrolled onto the Xamarin University course at the end of February and all things being equal I should be certified by the end of March.

So I declare 2014 to be my year of the mobile. I will still keep as current as I can with web development but the mobile market cannot be ignored and with a tool such as Xamarin I’m now in a position to take it on.