uploaded the companion slideshow here

Download Report

Transcript uploaded the companion slideshow here

Cross-platform mobile
development with c#
Greg Shackles - June 12, 2012
About Me
Greg
Shackles
Senior Software Engineer
OLO Online Ordering
email
[email protected]
twitter
@gshackles
github
github.com/gshackles
blog
Slides
gregshackles.com
speakerdeck.com/u/gshackles
the Book
oreil.ly/Lp5smR
Discount Code: AUTHD
Print Book: 40% Off
E-Book: 50% Off
Market Share (US): April 2012
50.8% Android
31.4% Apple
11.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
• Access to full platform SDKs
• 100% Native
• Linker
• frequent releases
• active community
• Improved API
xamarin.com
objc
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);
C#
var attrs = new CFStringAttributes {
Font = listLineCTFont,
ForegroundColor = UIColor.Black.CGColor
};
var astr = new NSAttributedString ("Hello World", attrs);
Ja
va
<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
}
}
);
[Activity(Label="@string/AppName", MainLauncher=true)]
C#
FindViewById<Button>(Resource.Id.Button).Click += delegate
{
// handle click
};
Environment: iOS
Mac OS X
MonoDevelop
Xcode
Integration
Environment: android
Mac OS X
MonoDevelop
Windows
Visual Studio
Environment: android
UI Designer: MonoDevelop and Visual Studio
Environment: windows phone
Windows
Visual Studio
Some Apps
icircuit
rdio
gmusic
c# to go
...and many more!
infinite flight
mwc 2012
Benefits
• Powerful and mature language
• Skill reuse
• Native apps
• Code reuse across platforms
even non-mobile platforms!
app Architecture
What code can be shared?
• Most non-UI or platform code
• Core application logic
• Entities
• LINQ (objects, XML)
• Network access
• File / Database Access *
* with some limitations
sharing techniques
• File Linking
• Abstraction
• Observer Pattern
• Partial Classes and Methods
• Conditional Compilation
• portable class libraries *
* currently in development
library: xamarin.mobile
Supports iOS, Android and Windows Phone
xamarin.com/mobileapi
Demo Time
Questions?