Greg Shackles - June 12, 2012
Cross-platform mobile
development with c#
About MeGreg
ShacklesSenior Software Engineer
OLO Online Ordering
twitter@gshackles
githubgithub.com/gshackles
bloggregshackles.com
Slidesspeakerdeck.com/u/gshackles
the Bookoreil.ly/Lp5smR
Discount Code: AUTHDPrint Book: 40% OffE-Book: 50% Off
Market Share (US): April 2012
50.8% Android31.4% Apple11.8% RIM 4.0% Microsoft
Source: comScore
native platform Languages
Objective-C
Java
C#
Write once, run anywhere
platform differences
!= !=
c# Everywhere
MonoTouch
Mono for Android
Native
The Power of C#•Base Class Library•LINQ•Parallel LINQ•Memory Management•Task Parallel Library•Dynamic
xamarin Tools
xamarin.com
•Access to full platform SDKs•100% Native•Linker•frequent releases•active community•Improved API
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);
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};
Environment: iOS
Mac OS X MonoDevelopXcode
Integration
Environment: android
Mac OS X
Windows
MonoDevelop
Visual Studio
UI Designer: MonoDevelop and Visual Studio
Environment: android
Environment: windows phone
Windows Visual Studio
Some Apps
...and many more!
icircuit rdio gmusic c# to go
infinite flight mwc 2012
•Powerful and mature language•Skill reuse•Native apps•Code reuse across platforms
Benefits
even non-mobile platforms!
app Architecture
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 *
sharing techniques
* currently in development
•File Linking•Abstraction•Observer Pattern•Partial Classes and Methods•Conditional Compilation•portable class libraries *
library: xamarin.mobile
Supports iOS, Android and Windows Phone
xamarin.com/mobileapi
Demo Time
Questions?