240 likes | 364 Vues
Join Greg Shackles, a Senior Software Engineer at OLO, as he dives into the world of cross-platform mobile development using C#. Explore the benefits of using C# across multiple platforms, including Android, iOS, and Windows Phone. Learn about essential tools like Xamarin, and discover how to efficiently share code with a focus on UI, core application logic, and network access. With practical examples and demos, Greg provides insights into developing native apps that maximize code reuse while taking advantage of the powerful features of C#.
E N D
Cross-platform mobile development with c# Greg Shackles - June 12, 2012
About Me Greg Shackles Senior Software Engineer OLO Online Ordering email greg@gregshackles.com twitter @gshackles github github.com/gshackles blog gregshackles.com Slides 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#
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
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 C# var attrs = new CFStringAttributes { Font = listLineCTFont, ForegroundColor = UIColor.Black.CGColor }; var astr = new NSAttributedString ("Hello World", attrs);
<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 C# [Activity(Label="@string/AppName", MainLauncher=true)] FindViewById<Button>(Resource.Id.Button).Click += delegate { // handle click };
Environment: iOS Xcode Integration Mac OS X MonoDevelop
Environment: android MonoDevelop Mac OS X Visual Studio Windows
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!
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