C# everywhere Building cross-platform apps with Xamarin Gill

Slides:



Advertisements
Similar presentations
Introduction to the Windows Runtime (WinRT) Ben Dewey Tallan, Inc.
Advertisements

Win8 on Intel Programming Course Desktop : Sensors Cédric Andreolli Intel Software
Amanda Silver Director of Program Management Visual Studio Tools for Client Applications Cross-Platform Development using Visual Studio.
Real world Windows Phone development Igor
Every company is a software company “CIOs will measure the impact of their business technology agenda based on the impact on the consumer – and not.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Microsoft Evangelist Presentation September 13, 2012.
The PhoneGap History Doncho Minkov Telerik Academy academy.telerik.com Technical Trainer
Mobile Development with Xamarin Mark Allan Ranyart
Introducing Xamarin 2.0 Introducing Xamarin 2.0 Michael Hutchinson
Mobile Application Development with ANDROID Tejas Lagvankar UMBC 29 April 2009.
Hot Tuna CROSS PLATFORM DEVELOPMENT WITH.NET, XAMARIN AND MVVMCROSS.
Title slide to be used at the start of a module. Developing Mobile Apps Roland Guijt
M1G Introduction to Programming 2 4. Enhancing a class:Room.
Developing Mobile Applications using MVVM with Xamarin Forms
Introduction to Silverlight. Slide 2 What is Silverlight? It’s part of a Microsoft Web platform called Rich Internet Applications (RIA) There is a service.
Lesley Bross, August 29, 2010 ArcGIS 10 add-in glossary.
@2011 Mihail L. Sichitiu1 Android Introduction Platform Overview.
Introduction to Mobile Programming. Slide 2 Overview Fundamentally, it all works the same way You get the SDK for the device (Droid, Windows, Apple) You.
Introducing NativeScript [Pavel Kolev Software Telerik: a Progress company]
Developing Cross-Platform Applications with Visual Studio 2015
Virtual techdays INDIA │ Nov 2010 Developing Office Biz Application using WPF on Windows 7 Sarang Datye │ Sr. Consultant, Microsoft Sridhar Poduri.
Developer TECH REFRESH 15 Junho 2015 #pttechrefres h Strategies for Developing Cross-Platform Applications Dinis Vieira.
Developing Native iOS, Android, and Windows apps in C# with Xamarin
Developing Enterprise Mobile Apps with Xamarin Loren Horsager CEO, Mobile Composer.
Microsoft SharePoint Server 2010 for the Microsoft ASP.NET Developer Yaroslav Pentsarskyy
Understanding Xamarin Development Matt
1 Geospatial and Business Intelligence Jean-Sébastien Turcotte Executive VP San Francisco - April 2007 Streamlining web mapping applications.
Mobile web Sebastian Lopienski IT Technical Forum 29 June 2012.
Microsoft UI Stack Ronnie Saurenmann Technical Evangelist, Microsoft Switzerland
Trunica Inc. 500 East Kennedy Blvd #300 Tampa, FL Cross Platform Mobile Apps With Cordova and Visual Studio 2015 © Copyright 2015.
The way of hybrid mobile development Hybrid Mobile Applications Telerik Software Academy
04 |Sharing Code Between Windows 8 and Windows Phone 8 in Visual Studio Ben Riga
 Can access all API’s made available by OS vendor.  SDK’s are platform-specific.  Each mobile OS comes with its own unique tools and GUI toolkit.
Introduction to Android OS Димитър Н. Димитров Astea Solutions AD.
If you are thinking about developing mobile application for your customer, this is an important aspect to consider the platform.
Exploring Networked Data and Data Stores Lesson 3.
/DEV/TM #1 Building Cross-Platform Apps with Xamarin and MvvmCross Flavius-Radu DEMIAN.
INTRODUCING HYBRID APP KAU with MICT PARK IT COMPANIES Supported by KOICA
Understanding the Xamarin Mobile Platform
Your Host & Speaker Shahed Chowdhuri Sr. Technical Microsoft Technology Areas Enterprise Web/Software Development Game Development Mobile.
The cutting edge event for ITPros and Devs December 7-8, 2013 Athens, Greece Fix it once use it everywhere Elias Markelis MCT, Windows Phone Enthusiast.
Build Hybrid Mobile Apps with Ionic, Angular, & Cordova Brian
The Basics of Android App Development Sankarshan Mridha Satadal Sengupta.
What is it all about? .NET MeetUp in Prague, CZ (2017/7/19)
Xamarin Development with
12/29/2017 2:33 PM © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN.
State of the Art in Mobile Development - AndRES Käver, 2016
Beginning of Xamarin for iOS development
Real world Windows Phone development
Introduction to Xamarin C# Everywhere
Microsoft Evangelist Presentation
State of the Art in Mobile Development
Xamarin Studio Xamarin Curriculum for Xamarin Studio
Android Studio, Android System Basics and Git
Basic Controls and Plugins
Apache Cordova Overview
Did your feature got in, out or planned?
1.1. .NET architectural components and .NET Core
MonoGame and Windows 8.
Introduction to Silverlight
Introduction to Xamarin C# Everywhere
.NET Standard Jon Galloway | Executive Director, .NET |
What is it all about? .NET MeetUp in Amsterdam, NL (2017/7/11)
Sviluppo mobile con Visual Studio OnLine
DotnetConf 11/14/2018 3:27 AM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE.
Microsoft Build /17/2018 2:10 PM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY,
Office 365 Development.
Microsoft Ignite /2/2019 1:15 AM Power Up Your Cross Platform Mobile Code with Platform Specific Features using Xamarin Alec Tucker MOB331 © 2015.
Build /23/2019 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Presentation transcript:

C# everywhere Building cross-platform apps with Xamarin Gill

Hi, I’m Gill! Gill Cleeren MVP and Regional Director.NET Ordina Trainer &

Agenda What is Xamarin then? Can I eat it? Code re-use: myth or reality? Shared projects: because sharing is caring, right? PCL where L stands for Love? And what about Xamarin.Forms?

What is Xamarin then? Can I eat it?

What is Xamarin? Xamarin enables developers to reach all major mobile platforms! Native User Interface Native Performance Shared Code Across Platforms C# &.NET Framework

What is Xamarin? Toolset on top of Visual Studio Output and build to Android, iOS and Windows Native apps Commercial product $2000/year for business subscriptions The “No-Compromise” approach

Advantages of using Xamarin Full control Familiar development environment Native controls Native performance Code reuse Active component store

Disadvantages of Xamarin You need a license It’s not a shared UI Platform You need to understand each platforms UI controls and UX paradigms You need a Mac for iOS dev

The promise: C#. Everywhere.

Silo’d Approach Build Apps Multiple Times Multiple Teams Multiple Code Bases Different toolsets

Write Once, Run Anywhere Approach Lowest common denominator Browser fragmentation Developing & designing for 1 platform, happen to get other platforms Black Box

Xamarin’s Unique Approach Native User Interface Native Performance Shared code across platforms C# &.NET Framework Full API Coverage

And where is C# coming into play then?

C# Is Awesome We (l) C#. This is why. LINQ Support Work With XML Easily XDocument Event Handling & Delegates

C# Is Awesome – JSON Made Easy We (l) C#. This is why.

See the Difference – Attributed Strings C# with XamarinObjective-C C# is a bit easier than Objective-C. A tiny bit.

C# with XamarinObjective-C C# is a bit easier than Objective-C. A tiny bit.

C# with XamarinJava C# & Async with Xamarin And compared to Java…

Write Beautiful & Maintainable Code We’ll wait here then.

Write Everything in C# iOS, Android, Windows, Windows Phone, Mac 2.5+ Billion Devices!

Anything you can do in Objective-C or Java can be done in C# and Visual Studio with Xamarin! 100% API Coverage

Android runtime model Mono VM + Java VM execute side-by-side (supports both Dalvik and ART) Mono VM JITs IL into native code and executes most of your code Can utilize native libraries directly as well as.NET BCL

iOS Runtime model Native ARMx code – no JIT is being used here Mono runtime provides system services such as Garbage Collection Full access to iOS frameworks such as MapKit as well as.NET BCL

DEMO Looking at a complete Xamarin application

Code re-use: myth or reality?

Code sharing in general Large chunks of the code we write are shareable between platforms Data access Service access Services “ViewModels” What isn’t shareable by default View/UI code Different situation with Xamarin.Forms… Event handlers Services bound the platform

Statistics from Xamarin for some “basic” apps

Code sharing options The ultimate goal is reaching an architecture as shown below A layered architecture will help us here!

Code sharing options Shared projects: allows organizing the shared code #if directives for platform specific code PCL “include” the platforms we want to support Abstract to interfaces where platforms have specific implementations

Creating a Xamarin cross-platform solution We start from an *.sln file (solution file) Make your choice: shared project or PCL Shared project: simply plugs in the code into each platform, use #if to control code execution PCL: Portable Class Library (PCL) is a special type of project that can be used across disparate CLI platforms such as Xamarin.iOS and Xamarin.Android, as well as Silverlight, WPF, Windows Phone and Xbox

Creating a Xamarin cross-platform solution

Platform divergence: Dealing with multiple platforms Some concepts are the same on all platforms Feature selection via tabs or menus Lists of data and scrolling Single views of data Editing single views of data Navigating back

Platform divergence: Dealing with multiple platforms On the other hand, some are platform-specific Screen sizes Navigation metaphors Keyboard Touch Gestures Push notifications

Platform divergence: Dealing with multiple platforms And then, some are device-specific We’ll need to write code to check if a feature is present or offer an alternative (map for location selection instead of GPS) Typical cases: Camera Geo-location Accelerometer, gyroscope and compass Twitter and Facebook Near Field Communications (NFC)

Dealing with divergence: Abstracting platforms Inheritance/base classes can be created in the shared projects Base functionality already created (cross-platform!) Limited somewhat since C# only allows base single inheritance Xamarin.Forms Uses a common, abstracted base for the UI creation Xamarin Mobile augments the.NET Base Class Libraries with a set of APIs that can be used to access device-specific features in a cross-platform way Media Picker: taking photos or selecting a media item Geolocation Address book access  Code can be written in shared code since it’s ignorant (for us) to the used platform

Dealing with divergence: divergent platform code Some cases won’t work with just abstraction Conditional compile can help out __MOBILE__ is true for iOS and Android projects __IOS__ can be used to detect iOS devices __ANDROID__ can be used to detect Android devices __ANDROID_XX__ can be used to detect specific Android API version __ANDROID_11__ __WINDOWS_PHONE__ and __SILVERLIGHT__ can be used to detect Windows Phone devices

Using precompiler statements public static string DatabaseFilePath { get { var filename = "MwcDB.db3"; #if SILVERLIGHT var path = filename; #else #if __ANDROID__ string libraryPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); ; #else // we need to put in /Library/ on iOS5.1 to meet Apple's iCloud terms // (they don't want non-user-generated data in Documents) string documentsPath = Environment.GetFolderPath (Environment.SpecialFolder.Personal); // Documents folder string libraryPath = Path.Combine (documentsPath, "..", "Library"); #endif var path = Path.Combine (libraryPath, filename); #endif return path; }

DEMO Xamarin.Mobile

Shared projects

Before Shared Projects… We could use file linking Add existing item >> Add as Link File isn’t duplicated, instead, it lives in the original location only When compiling, it is part of the compiled output Can include precompiler statements to have different behaviour on different OS’s Disadvantage: refactoring not ideal + testing not great

Today: Shared Projects AKA Shared Resource Projects Allow writing code which is shared between multiple target projects incl Xamarin New project type makes it possible to share on project-level IDE knows this, supports this Also supports precompiler statements Different coloring based on the application Only 1 copy of the file exists Supports testing and refactoring Supported since XS 5 and VS 2013 Update 2 Also works with Windows Phone 8 and Windows 8.1

Shared Projects internals Shared project has no DLL output Code gets compiled in each project which references it Project gets copied into each referencing project

DEMO Shared projects

PCLs

What’s a PCL then? When creating a regular project, the DLL is restricted to that platform only By default, a WP8 Class Library won’t work from Xamarin A PCL overcomes this: we can choose the platforms we want our code to run on Choices are the Profile identifier: describes which platforms are supported Based on selection, features may/may not be available

Selecting the right targets Only select the targets you need in your application. This will give you a broader API!  This selects the profile!

Missing profiles Not all combinations are allowed, simply because they aren’t defined by Microsoft IDE will try to select the closest match (or an error if you have done something you shouldn’t )

Advantages of PCLs Centralized code sharing – write and test code in a single project that can be consumed by other libraries or applications Refactoring operations will affect all code loaded in the solution (the Portable Class Library and the platform-specific projects) The PCL project can be easily referenced by other projects in a solution, or the output assembly can be shared for others to reference in their solutions

Disadvantages of PCLs Because the same Portable Class Library is shared between multiple applications, platform-specific libraries cannot be referenced (eg. Community.CsharpSqlite.WP7) The Portable Class Library subset may not include classes that would otherwise be available in both MonoTouch and Mono for Android (such as DllImport or System.IO.File)  Using abstractions (DI or Provider pattern) can help circumventing some of these restrictions!

Going around PCL limitations PCLs uses the smallest common denominator All features in the PCL (and the profile) must be available on all targets By default, no support for File, SteamReader… Solutions: Rely on what’s there (often lower-level abstractions) Build your PCL with abstractions (interface, events…) and implement the abstraction in your platform specific code Events Concrete implementations of interfaces IOC

DEMO PCLs

And what with Xamarin.Forms?

So what is Xamarin.Forms really? Xamarin.Forms is a cross-platform natively backed UI toolkit abstraction that allows developers to easily create user interfaces that can be shared across Android, iOS, and Windows Phone Allows rapid development of cross-platform UIs Abstraction on top of UI elements More code sharing than ever before Still native apps Still native performance and look and feel

With Xamarin.Forms With Xamarin.Forms: more code-sharing, native controls Shared UI Code

Main features RAD, forms-based app creation 40+ Pages, Layouts, and Controls Build from code behind or XAML Two-way Data Binding Navigation Animation API Dependency Service Messaging Center Support for Android 4.0+ iOS 6.1+ Windows Phone 8.0+ (Silverlight only) Shared UI Code

Getting started Resulting solution: Note that XS doesn’t support the WP8 currently Will open but not load/compile Shared Project or PCL holds shared code, used by all other projects iOS, Android and WP8 projects contain platform-specific UI code

DEMO Code sharing with Xamarin.Forms

Creating a XAML-based application Add a XAML file (ContentPage) Also creates the code-behind

DEMO XAML-based Xamarin.Forms

Summary Xamarin == native cross platform Strong backing of shared projects and PCLs help code re-use Xamarin.Forms goes the extra mile Still somewhat limited though