xamarin open house talk - sela group - ofir makmal
Post on 07-May-2015
1.151 Views
Preview:
DESCRIPTION
TRANSCRIPT
© 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: Ofirm@sela.co.ilBlog: http://blogs.microsoft.co.il/ofirmakmalTwitter: @OfirMakmalLinkedIn: http://www.linkedin.com/in/ofirmakmal
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
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
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%
iOS Basic Concepts
Foundation/UIKit
View controllers
Storyboards and segues
Table views
Android Basic Concepts
Android SDK
Activities
Intents
ListViews and adapters
Windows Runtime Basic Concepts
.NET Framework
Pages
Navigation
ListViews and binding
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
What's out there?
What about performance, UX, Look&Feel?
What Is PhoneGap All About?Wrapper
Bridge
Write C#. Run on 2.5 billion devices.
Introducing Xamarin
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
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?
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
Demo
Xamarin stack
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
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
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
Xamarin Application Architecture
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
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)
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!
Portable Class Library – cont.
Portable Class Library – cont.
Almost every package on NuGet comes with PCL
HttpClientImmutable CollectionsSignalRODataLibRESTSharpJson.NetMvvmCrossTinyIoCProtobuf-netMany more..
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
Demo
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
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
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)
Demo
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
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
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
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
ShowcaseBastion
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/
Demo
Licensing
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!)
Questions
Thank you!
If you can do it in Objective-C and Java, you can do it in C# with Xamarin.
Ofir Makmal - Senior ConsultantEmail: Ofirm@sela.co.ilBlog: http://blogs.microsoft.co.il/ofirmakmalTwitter: @OfirMakmalLinkedIn: http://www.linkedin.com/in/ofirmakmal
top related