Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to Xamarin 2.0

Introduction to Xamarin 2.0

Introduction to Xamarin 2.0 at Miracle Open World 2013 - http://mow2013.dk

Chris Hardy

May 02, 2013
Tweet

More Decks by Chris Hardy

Other Decks in Technology

Transcript

  1. Chris Hardy • .NET Contractor • Work with Xamarin •

    Wrote some books • First spoke about MonoTouch in January 2010 • http://twitter.com/chrisntr
  2. • C# and .NET for Android, iOS and Mac •

    Full native APIs – no compromise • Share code across Android, iOS, Mac, Windows Phone, Windows RT, Windows • Only platform that allows sharing code across these platforms while keeping native performance and UX What is Xamarin?
  3. • New Pricing - An edition for every developer •

    New Names - Xamarin.iOS, Xamarin.Android, Xamarin.Mac • Developer Center • Massively revamped documentation website • World class tutorials and guides What’s New in 2.0?
  4. • Free Starter Edition • 32kb of user IL, can’t

    link native code • Indie Edition • Unrestricted size and native linking • Business Edition • Visual Studio, WCF, email support • Enterprise • App kickoff, priority support, free components • Trial Xamarin Editions
  5. • Xamarin Studio The best IDE for mobile development •

    iOS for Visual Studio Develop iOS apps from VS on Windows • Component Store Drop-in components to build apps faster What’s New in 2.0?
  6. Xamarin Studio • Fast, smooth C# code navigation, completion and

    refactoring • Git and subversion integration • Powerful debugger • Available on Windows and Mac
  7. iOS for Visual Studio • You asked for it, we

    delivered! • Write, build, deploy and debug iOS apps from Visual Studio • Take advantage of existing skills and extensions, for example TFS and ReSharper • Develop for iOS, Android, Windows Phone from a single solution
  8. iOS for Visual Studio • Connects to Mac over network

    • Seamlessly transfers compiled C# to Mac for native build, sign • Launch and debug on simulator or device
  9. Component Store • Paid and free components • Add Components

    to your app directly from within XS or VS • Submit your own!
  10. Xamarin Evolve 2013 • C# 5.0 / async - await

    • F# support • Test Cloud • iOS Designer
  11. Today • C# 5.0 / async - await • iOS

    Designer • C# 5.0 / async - await • F# support • Test Cloud • iOS Designer
  12. Callbacks Are Today’s goto Statement 01 02 03 04 05

    06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 void  Refresh  () {        DownloadTweets  (OnTweetsDownloaded); } void  OnTweetsDownloaded  (Tweet  []  tweets) {        if  (tweets  ==  null)  {                ShowError  ("Error  downloading");        }  else  {                AddTweetsToScreen  (tweets);                DownloadAttachments  (tweets);        } } void  DownloadAttachments  (Tweet  []  tweets) {        foreach  (var  tweet  in  tweets)  {                  var  tweetUI  =  CreateTweetView();                if  (tweet.HasAvatar)  {                        Download  (tweet.AvatarUrl,  avatar  =>  {                                if  (avatar  ==  null)                                        return;                                InvokeOnMainThread  (()  =>  {                                        tweetUI.Avatar  =  avatar;                                });                        });                }                if  (tweet.HasImageAttachment)  {                        Download  (tweet.ImageUrl,  img  =>  {                                if  (img  ==  null)                                        return;                                InvokeOnMainThread  (()  =>  {                                        tweetUI.ImgAttachment  =  img;                                });                        });                }                if  (tweet.HasGeolocation)  {                        GeoLocation.ReverseLookup  (tweet.Location,  location  =>  {                                if  (location  ==  null)                                        return;                                InvokeOnMainThread  (()  =>  {                                        tweetUI.DisplayedLocation  =  location;                                });                        });                }        } }
  13. C# 5.0 Async async  Task  RefreshAsync() {      

     var  tweets  =  await  DownloadTweetsAsync();        if  (tweets  ==  null)                return;        foreach  (var  tweet  in  tweets)  {                var  tweetView  =  CreateTweetView();                if  (tweet.HasAvatar)                        tweetView.Avatar  =  await  DownloadAsync  (tweet.AvatarUrl);                if  (tweet.HasImageAttachment)                        tweetView.ImgAttachment  =  await  DownloadAsync  (tweet.ImageUrl);                if  (tweet.HasGeolocation)                        tweetView.DisplayedLocation  =  await  GeoLocation.ReverseLookupAsync   (tweet.Location);        } }
  14. Async in C# • New major feature of C# 5.0

    Makes asynchronous programming a first- class citizen in C# Important part of C# – as significant as LINQ • New async modifier keyword introduced • Methods, lambda expressions, and anonymous methods can be asynchronous • New contextual keyword await introduced
  15. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 17 Calculating a Price public  async  Task<int>  CalculatePriceAsync  (Item[]  items) { using  (var  cmd  =  CreateSqlCommand   (Calculations.TotalPrice,  items))  { using  (var  reader  =  await  cmd.ExecuteReaderAsync  ())  { int  price  =  ReadPrice  (reader); return  price; } } } public  override  void  ViewDidLoad  () { button.TouchDown  +=  async  (sender,  e)  =>  { var  price  =  await  CalculatePriceAsync  (items); priceLabel.Text  =  price.ToString  (); }; }
  16. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 Exception Handling with Await public  override  void  ViewDidLoad  () { button.TouchDown  +=  async  (sender,  e)  =>  { try  { button.Enabled  =  false; var  price  =  await  CalculatePriceAsync  (items); priceLabel.Text  =  price.ToString  (); }  catch  (Exception  ex)  { //  Handles  price  calculation  error priceLabel.Text  =  "Calculation  failed"; Debug.Print  (ex.ToString  ());  //  Simple  exception   logging }  finally  { button.Enabled  =  true; } };
  17. 01 02 03 04 05 06 07 08 09 10

    11 12 13 14 15 16 Exception Throwing public  async  Task<int>  CalculatePriceAsync  (Item[]  items) { if  (items  ==  null)  { //  Throw  before  suspension throw  new  ArgumentNullException  ("items"); } ... var  price  =  await  CalculatePriceAsync  (items); if  (price  <  0)  { //  Throw  after  suspension throw  new  ArgumentException  ("Invalid  items"); } ... }
  18. Get Your Hands on Async • Async is available today

    Xamarin.iOS Beta release Xamarin.Android Beta release Xamarin Studio async support • Give us feedback on our new async API Forums Bugzilla
  19. It’s all about sharing code Shared C# Code Xamarin.Mobile Business

    Logic Cloud Access Database Access Desktop Desktop Mobile Mobile Mobile Windows iOS Windows Phone Android Mac
  20. TouchDraw runs on iPad, Android, and Mac, achieving over 70%

    code reuse across the platforms. 39% 61% TouchDraw for iPad 24% 76% TouchDraw for Mac 28% 72% TouchDraw for Android Shared Code Platform Specific
  21. Xamarin.Mac at a glance • Write native Mac applications in

    C# • Access Mac OS X APIs for rich integration • Leverage the full power of C# and .NET • Integrated with the Xamarin experience • Deploy directly to the Mac AppStore
  22. Xamarin.Mac at a glance Xamarin.Mac Frameworks Xamarin Tools and SDK

    • Binder • Bundler • Linker • Packager Mono Runtime .NET Base Class Libraries System Libraries Darwin OS Cocoa Frameworks Xcode (UI designer) Xamarin Studio IDE
  23. How does Xamarin.Mac work? • OS X APIs are projected

    into C# 1:1 mapping for full platform coverage • 80% are Objective-C Full object system is mapped Subclassing and overriding supported • 20% are C Exposed as C# structs/classes/methods No support for subclassing or overriding