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

Cross-Platform Mobile Development with C# (MonkeySpace 2012)

Cross-Platform Mobile Development with C# (MonkeySpace 2012)

Greg Shackles

October 18, 2012
Tweet

More Decks by Greg Shackles

Other Decks in Programming

Transcript

  1. Greg Shackles
    Cross-platform mobile
    development with c#

    View full-size slide

  2. About Me
    Greg Shackles
    Senior Software Engineer
    OLO Online Ordering
    email
    [email protected]
    twitter
    @gshackles
    github
    github.com/gshackles
    blog
    gregshackles.com
    Slides
    speakerdeck.com/u/gshackles

    View full-size slide

  3. nycmobiledev.net
    @NYCMobileDev

    View full-size slide

  4. the Book
    oreil.ly/Lp5smR
    Discount Code: AUTHD
    Print Book: 40% Off
    E-Book: 50% Off

    View full-size slide

  5. Market Share (US): August 2012
    Google Apple RIM Microsoft Symbian
    52.6% Android
    34.3% Apple
    8.3% RIM
    3.6% Microsoft
    Source: comScore

    View full-size slide

  6. native platform Languages
    Objective-C
    Java
    C#

    View full-size slide

  7. Write once, run anywhere

    View full-size slide

  8. "The biggest mistake we made as a
    company was betting too much on
    HTML5 instead of native."
    - Mark Zuckerberg

    View full-size slide

  9. Embrace the differences
    != !=

    View full-size slide

  10. c# Everywhere
    MonoTouch
    Mono for Android
    Native

    View full-size slide

  11. The Power of C#
    •Base Class Library
    •LINQ
    •Parallel LINQ
    •Memory Management
    •Task Parallel Library
    •Dynamic
    •Skill Reuse

    View full-size slide

  12. xamarin Tools
    •Access to full platform SDKs
    •100% Native
    •Linker
    •Debugging
    •frequent releases
    •active community
    •Improved API

    View full-size slide

  13. C#
    CFStringRef  keys[]  =  {
           kCTFontAttributeName,
           kCTForegroundColorAttributeName
    };
     
    CFTypeRef  bval[]  =  {
           cfListLineCTFontRef,
           CGColorGetConstantColor(kCGColorBlack)
    };
     
    attr  =  CFDictionaryCreate  (
           kCFAllocatorDefault,
           (const  void  **)  &keys,  (const  void  **)  &bval,
           sizeof(keys)  /  sizeof(keys[0]),  &kCFTypeDictionaryKeyCallBacks,
           &kCFTypeDictionaryValueCallBacks);
     
    astr  =  CFAttributedStringCreate(
    kCFAllocatorDefault,  CFSTR("Hello  World"),  attr);
    obj-c
    var  attr  =  new  CFStringAttributes  {
           Font  =  listLineCTFont,
           ForegroundColor  =  UIColor.Black.CGColor
    };
     
    var  astr  =  new  NSAttributedString  ("Hello  World",  attrs);

    View full-size slide

  14. C#
               android:label="@string/app_name">
     
       
       
     

    findViewById(R.id.button).setOnClickListener(
    new  View.OnClickListener()  
           {
                 @Override
         public  void  onClick(View  v)
         {
                 //  handle  click
         }
           }
    );
    Java
    [Activity(Label="@string/AppName",  MainLauncher=true)]
    FindViewById(Resource.Id.Button).Click  +=  delegate  
    {
      //  handle  click
    };

    View full-size slide

  15. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    UI and Platform Code
    Shared Code

    View full-size slide

  16. What code can be shared?
    * with some limitations
    •Most non-UI or platform code
    •Core application logic
    •Entities
    •LINQ (objects, XML)
    •Network access
    •File / Database Access *

    View full-size slide

  17. sharing techniques
    •File Linking
    •Abstraction
    •Observer Pattern
    •Partial Classes and Methods
    •Conditional Compilation
    •portable class libraries

    View full-size slide

  18. library: xamarin.mobile
    Supports iOS, Android and Windows Phone
    xamarin.com/mobileapi

    View full-size slide

  19. Case Study: iCircuit

    View full-size slide

  20. http://praeclarum.org/post/31799384896/icircuit-code-reuse-the-fourth-edition
    16%
    84%
    Shared Platform
    31%
    69%
    13%
    87%
    iOS
    WP7
    Mac
    19%
    81%
    Android
    Case Study: iCircuit

    View full-size slide

  21. Case Study: TouchDraw

    View full-size slide

  22. http://lipsky.me/2012/9/11/touchdraw-code-reuse-updated
    39%
    61%
    Shared Platform
    24%
    76%
    28%
    72%
    iOS Mac Android
    Case Study: TouchDraw

    View full-size slide

  23. SignalR Client Libraries
    http://github.com/gshackles/SignalR
    C# To Go
    Mono.CSharp
    http://github.com/gshackles/CSharpToGo
    Case Study: Class Libraries

    View full-size slide