![Page 1: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/1.jpg)
© Copyright SELA software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com
Building Cross-Platform applications using Xamarin and C#Open House – January 2014
Ofir Makmal - Senior ConsultantEmail: [email protected]: http://blogs.microsoft.co.il/ofirmakmalTwitter: @OfirMakmalLinkedIn: http://www.linkedin.com/in/ofirmakmal
![Page 2: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/2.jpg)
Mobile Market ReviewiOS vs Android vs Windows (Phone\Store)JavaScript, CSS, HTML 5 alternative Xamarin approachThe magic behindCross-Platform Application ArchitectureCode-Sharing ‘tactics’Components store/open source componentsTips, tricks and others caveats
Agenda
![Page 3: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/3.jpg)
Mobile Platforms
iOS• Storyboards• Objective C• Xcode
Android• XML-based UI• Java• Eclipse/Android
Studio/IntelliJ IDEA
Windows Phone/Windows 8• XAML-based UI• C#, VB, C++,
JavaScript• Visual Studio
![Page 4: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/4.jpg)
OS Versions
Windows Phone 8;
70%
Windows Phone 7.x;
30%
iOS 7; 74%
iOS 6; 22%
Earlier; 4%
KitKat (4.4); 1.10%
JellyBean (4.1-4.3); 54.50%
ICS (4.0.x); 18.60%
Honeycomb (3.x); 0.10%
Gingerbread (2.3.x); 24.10%
Froyo (2.2); 1.60%
![Page 5: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/5.jpg)
iOS Basic Concepts
Foundation/UIKit
View controllers
Storyboards and segues
Table views
![Page 6: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/6.jpg)
Android Basic Concepts
Android SDK
Activities
Intents
ListViews and adapters
![Page 7: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/7.jpg)
Windows Runtime Basic Concepts
.NET Framework
Pages
Navigation
ListViews and binding
![Page 8: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/8.jpg)
Targeting all major platforms
Theoretically, can provide the best UX, but
Comes with a great costAcquire specialties with at list three different technologiesNo code sharingEvery feature, bug, needed to be implemented several times
![Page 9: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/9.jpg)
What's out there?
![Page 10: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/10.jpg)
What about performance, UX, Look&Feel?
What Is PhoneGap All About?Wrapper
Bridge
![Page 11: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/11.jpg)
Write C#. Run on 2.5 billion devices.
Introducing Xamarin
![Page 12: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/12.jpg)
Xamarin
Founded in 2011 by Novell ex-employees
Based on the Mono project – launched on 2001
Brings the .NET Framework to Linux and OS XStable, great performance, tooling, huge code base
Xamarin took it to the next step: all major platforms – iOS, Android, Linux, OS X
![Page 13: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/13.jpg)
Write in C#Write in C#!!
100% platform API coverageSame-day support for all new API’s Average of 75% code sharing!
You can keep using Visual StudioAnd your favorite extensionsor you can use the free Xamarin Studio
All latest C# goodness – LINQ, async\await, TPL
Why Xamarin?
![Page 14: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/14.jpg)
Boring, yet important
Officially partnered with MicrosoftMSDN special plans
Over 460,000 developers live, 20,000 paying customers, 120 consulting partners
Used by more than 20% of Fortune 500 companies
Great documentation and tutorialsVery responsive community and forumsReuse your company’s current development investment
![Page 15: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/15.jpg)
Demo
![Page 16: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/16.jpg)
Xamarin stack
![Page 17: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/17.jpg)
Where is the magic?
Xamarin.iOS - full Ahead-of-Time (AOT) compilation to produce an ARM binary suitable for Apple's App Store.Xamarin.Android - takes advantage of Just In Time compilation right on the Android device
![Page 18: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/18.jpg)
Xamarin on iOS (monoTouch)AOT – Ahead Of Time compilation (no JIT)Support ARMv6, ARMv7, ARMv7sCan use the LLVM optimizing compilerUses mtouch
Static analysis-based linkerOnly dependent components are being compiled and deployedReduce the size of the application dramaticallyCan be disabled using flags (No Link, Link SDK Only) or manually using attributes
From Apple perspective – Xamarin application is like any other native application on the AppStore
![Page 19: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/19.jpg)
Xamarin on Android (monoDroid)
Runs both Dalvik and CLR at the same timeSimilar linker as to iOS – reduce the application size in up to 70%
Can be disabled using flags (No Link, Link SDK Only) or manually using attributes
Mono JIT-CompilingMono’s Simple Generational GC
See tips and tricks
Interaction with the OS is done using JNI (Java Native Interface) with Managed runtime wrappers
![Page 20: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/20.jpg)
Xamarin Application Architecture
![Page 21: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/21.jpg)
User Interface Designer
AndroidAXml editorAll standard android UI controlsBuilt-in – both Visual Studio and Xamarin Studio
iOSXCode UI designerStoryboards also supportedXamarin works directly with the XIB fileIntegrated designer – in Alpha
![Page 22: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/22.jpg)
Code sharing ‘tactics’
File-LinkingUsing symbolic links to shared files from different projectsGenerally used with conditional compilation directivesCan be used with partial classes and methods
Can be hard to unit-testRequires an extra step for building the core project
Portable Class Library (PCL)
![Page 23: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/23.jpg)
Portable Class Library
Support various deployment targetsWindows 7\8 Desktop appsWindows 8 Store AppsWindows Phone 7\8Xamarin.iOSXamarin.AndroidXbox (partial)Silverlight 4\5
All by using the same binary!
![Page 24: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/24.jpg)
Portable Class Library – cont.
![Page 25: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/25.jpg)
Portable Class Library – cont.
Almost every package on NuGet comes with PCL
HttpClientImmutable CollectionsSignalRODataLibRESTSharpJson.NetMvvmCrossTinyIoCProtobuf-netMany more..
![Page 26: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/26.jpg)
MvvmCross
By far the best and most robust Mvvm framework Supports:
Xamarin.iOSXamarin.AndroidWindows PhoneWindows Store AppsWPF Mac OS X
Navigation, IoC container, bindings, etc.. – One stop shop
![Page 27: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/27.jpg)
Demo
![Page 28: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/28.jpg)
Visual Studio Integration
iOS application can be developed in Visual Studio, but you will still need a Mac
For building the binariesRunning the simulatorDeploy to deviceUI using Xcode (Interface Builder)
Works perfectly side-by-side – using remote build and deployment
F5 on VS, the application is loaded on the iOS simulator\device
![Page 29: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/29.jpg)
Visual Studio Integration – cont.
Android works within VS as any other C# projectSimulator needs some tweaks for performance
Intel HAXM
Device deployment is the fastest
![Page 30: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/30.jpg)
Xamarin Studio (monoDevelop)
Fully featured, modern IDEGlobal type searchCode NavigationBoth Mac and Windows versionsMuch more..
NuGet supportSource control
SVN / GIT are supported
Refactoring in Visual Studio is better
Generally, great IDE (really)
![Page 31: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/31.jpg)
Demo
![Page 32: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/32.jpg)
Geo-Location
Address book
using Xamarin.Geolocation;var locator = new Geolocator { DesiredAccuracy = 50 };
Position position = await locator.GetPositionAsync (timeout: 10000);
// position.Latitude, position.Longitude, etc..
using Xamarin.Contacts;var contacts = new AddressBook ();
if (await book.RequestPermission()) {contacts.OrderBy(c => c.LastName).ForEach(c => Console.WriteLine);}
Xamarin.Mobile
![Page 33: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/33.jpg)
PushSharp
Server-side library for sending Push NotificationsiOS (iPhone/iPad APNS)Android (C2DM and GCM - Google Cloud Message)Windows PhoneWindows 8Amazon, Blackberry too
http://tinyurl.com/pushsharpsession
![Page 34: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/34.jpg)
InteroperabilityUse native libraries as if they were written in C#
You can wrap a driver for any specific platform and use it in Xamarin – specific printer, scanner, etc..
iOS Objective Sharpie – for semi-automatic wrapper generation for Objective-C drivers
Android – set build action to AndroidNativeLibrary and use PInvoke
![Page 35: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/35.jpg)
tips
Good separation between UI code and BLE.g. Do not use BitmapImage on your BL
Whatever you do, do not use MEFAbstract away the IoC implementation
Create abstractions for system.configurationiOS - Reflection and mtouch linker issuesAndroid – Large object graphs on Java.Lang.Object subclassesAndroid – Use the x86 emulator (!)
Make your app Xamarin-friendly
![Page 36: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/36.jpg)
ShowcaseBastion
![Page 37: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/37.jpg)
3rd party components
There is a component for almost every need
Google Play ServicesWindows Azure Mobile ServicesFacebook SDKTwitter SDKPushSharp - TBDRestSharpMany more - http://components.xamarin.com/
![Page 39: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/39.jpg)
Demo
![Page 40: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/40.jpg)
Licensing
![Page 41: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/41.jpg)
Getting started with Xamarin
Scan your code for conformance: scan.xamarin.comDownload:
Trial program – 30 daysMSDN Subscription benefit – 90 days
Tons of webinars from the last conferenceGreat tutorials (really!)
![Page 42: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/42.jpg)
Questions
![Page 43: Xamarin Open House talk - Sela Group - Ofir Makmal](https://reader036.vdocuments.net/reader036/viewer/2022062702/554a4a6fb4c905863d8b5795/html5/thumbnails/43.jpg)
Thank you!
If you can do it in Objective-C and Java, you can do it in C# with Xamarin.
Ofir Makmal - Senior ConsultantEmail: [email protected]: http://blogs.microsoft.co.il/ofirmakmalTwitter: @OfirMakmalLinkedIn: http://www.linkedin.com/in/ofirmakmal