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

Cross-Platform Mobile Development with C#

Cross-Platform Mobile Development with C#

The mobile space continues to heat up, but every platform has its own language and set of tools you must use if you want to deliver a fully native experience to your users. Did you know that you can actually use C# and the .NET Framework to build native applications for iOS, Android and Windows Phone? Using C# and .NET across the board also means that you have the opportunity to share large amounts of code between platforms.

This session will introduce you to:

Developing cross-platform mobile applications using C#
Making use of MonoTouch and Mono for Android for iOS and Android
And exploring how they relate to the native platform libraries

Greg Shackles

June 09, 2012
Tweet

More Decks by Greg Shackles

Other Decks in Programming

Transcript

  1. 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
  2. Market Share (US): April 2012 Google Apple RIM Microsoft Symbian

    50.8% Android 31.4% Apple 11.8% RIM 4.0% Microsoft Source: comScore
  3. The Power of C# •Base Class Library •LINQ •Parallel LINQ

    •Memory Management •Task Parallel Library
  4. The Power of C# •Base Class Library •LINQ •Parallel LINQ

    •Memory Management •Task Parallel Library •Dynamic
  5. xamarin Tools xamarin.com •Access to full platform SDKs •100% Native

    •Linker •frequent releases •active community
  6. xamarin Tools xamarin.com •Access to full platform SDKs •100% Native

    •Linker •frequent releases •active community •Improved API
  7. 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
  8. 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  attrs  =  new  CFStringAttributes  {        Font  =  listLineCTFont,        ForegroundColor  =  UIColor.Black.CGColor };   var  astr  =  new  NSAttributedString  ("Hello  World",  attrs);
  9. <activity  android:name=".SampleActivity"            android:label="@string/app_name">   <intent-­‐filter>

        <action  android:name="android.intent.action.MAIN"  />     <category  android:name="android.intent.category.LAUNCHER"  />   </intent-­‐filter> </activity> findViewById(R.id.button).setOnClickListener( new  View.OnClickListener()          {                @Override      public  void  onClick(View  v)      {              //  handle  click      }        } ); Java
  10. C# <activity  android:name=".SampleActivity"            android:label="@string/app_name">  

    <intent-­‐filter>     <action  android:name="android.intent.action.MAIN"  />     <category  android:name="android.intent.category.LAUNCHER"  />   </intent-­‐filter> </activity> findViewById(R.id.button).setOnClickListener( new  View.OnClickListener()          {                @Override      public  void  onClick(View  v)      {              //  handle  click      }        } ); Java [Activity(Label="@string/AppName",  MainLauncher=true)] FindViewById<Button>(Resource.Id.Button).Click  +=  delegate   {   //  handle  click };
  11. •Powerful and mature language •Skill reuse •Native apps •Code reuse

    across platforms Benefits even non-mobile platforms!
  12. What code can be shared? •Most non-UI or platform code

    •Core application logic •Entities
  13. What code can be shared? •Most non-UI or platform code

    •Core application logic •Entities •LINQ (objects, XML)
  14. What code can be shared? •Most non-UI or platform code

    •Core application logic •Entities •LINQ (objects, XML) •Network access
  15. 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 *
  16. sharing techniques * currently in development •File Linking •Abstraction •Observer

    Pattern •Partial Classes and Methods •Conditional Compilation •portable class libraries *