Tag Archives: Xamarin

TechEd Demo Video Available Online

As previously announced I presented a session at TechEd Australia 2013 and anyone who came along will know I had some challenges with the demo component of my talk on the day. I thought it would be great to actually show you all how the demo *should* have run on the day, so to that end I’ve recorded a screencast that runs through the entire demo with a few tips and tricks along the way. I recommend you run it full screen!

You can also grab the sourcecode from this demo here: https://github.com/sjwaight/techedau2013

The video is available on YouTube here: http://youtu.be/QQO3r0myTd4 (and is embedded below).

Tagged , , , , ,

Portable Azure Mobile Services DTOs when using Xamarin and C#

As part of an upcoming talk I am giving I am spending a lot of time working on a demo that shows how to do push notifications cross-device. One concept that is really drummed in when working in this space is that building reusable C# is key to leveraging the savings from building Windows Phone, iOS, Android apps this way.

A C# Azure Mobile Services client library exists for each of the platforms and it’s really easy to use your standard C# classes as Data Transfer Objects (DTOs) for storage in Azure as a result. One item that tripped me up on Android and iOS was that I found I could write data to the cloud easily and while I could get a set of resulting objects back their properties were either null or in their default state. Not useful!

This is how my class looked – I had arrived at this after using DataMember and JsonProperty objects and finding, at first appearances, that I didn’t need either for the code to actually work. I was wrong :).

public class Task : IBusinessEntity
{
     public Task () {}

     public int ID { get; set; }
     public string Name { get; set; }
     public string Notes { get; set; }
     public bool Done { get; set; }
     public string Assignee { get; set; }
}

The challenge in decorating the above class with DataMember is that this class isn’t actually natively supported on Windows Phone – you will get a NotSupportedException the first time your application attempts to run any code that uses this class. The suggested fix in the Exception is to utilise the JsonProperty attribute instead which doesn’t actually work on Android or iOS deployment. So… this is the fix I came up with – it’s not pretty but it is leveraging one way to build portable C# code (note there is no default symbol defined for iOS builds which doesn’t help!) Behold…

public class Task : IBusinessEntity
{
    public Task () {}

    public int ID { get; set; }

#if !WINDOWS_PHONE
    [DataMember(Name = "name")]
#endif
    public string Name { get; set; }

#if !WINDOWS_PHONE
    [DataMember(Name = "notes")]
#endif
    public string Notes { get; set; }

#if !WINDOWS_PHONE
    [DataMember(Name = "done")]
#endif
    public bool Done { get; set; }

#if !WINDOWS_PHONE
    [DataMember(Name = "assignee")]
#endif
    public string Assignee { get; set; }
}

I think you’ll find that compiler pre-processor directives like this will quickly become your friend when writing C# to target multiple platforms.

Tagged , , , , , ,

Debug iOS App from Visual Studio with Xamarin extension using the iPhone Simulator.

This is a really quick and easy tip for those starting out doing iOS development with Xamarin (and specifically with the Visual Studio extensions). If you don’t have access to an iOS device and want to debug on the Simulator that ships with Xcode make sure you do the following:

Set the “Platform” to “iPhoneSimulator” for the project.

1. Select the Solutions Configuration menu (allows you typically to choose Debug or Release) and is next to the “Start” debug button.
2. In the Configuration Manager for your iOS App select “Platform” and change to “iPhoneSimulator” (highlighted below).
3. Save the changes and you should now be able to debug.

Selecting iPhoneSimulator

I scratched my head on this for a while ;).

BTW, did I say how cool it is that you can develop Android and iOS apps from right inside Visual Studio? You still need a Mac and Xcode for iOS but Android is there for the taking (you can even edit the axml layout files directly inside Visual Studio!)

Tagged , , , ,