Top Banner
Develop Business Apps Cross-platform development using Visual Studio with Xamarin and Azure Alexander Meijers| SharePoint Lead Architect Tuesday, April 14th 2015
55

Develop business apps cross-platform development using visual studio with xamarin and azure

Jul 16, 2015

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Develop business apps   cross-platform development using visual studio with xamarin and azure

Develop Business AppsCross-platform development using Visual Studio

with Xamarin and Azure

Alexander Meijers| SharePoint Lead Architect

Tuesday, April 14th 2015

Page 2: Develop business apps   cross-platform development using visual studio with xamarin and azure

Agenda

• Where to start?

• Development• Cross platform

• Programming skills

• Development environment

• Windows Azure

• Known issues

• Takeaways & Roundup

• Resources

Page 3: Develop business apps   cross-platform development using visual studio with xamarin and azure

Where to start?

• Considerations

• Type of Business Apps

Page 4: Develop business apps   cross-platform development using visual studio with xamarin and azure

Considerations

• Targeting• Single platform

• Cross platform

• Deployment• Development versus production

• Release management

• Hosting of the App

• App Store or not to Store

• Other• Localization

• Design

• Interaction

• Security

• Data storage• Local storage in App

• Storage in the cloud

• Hybrid scenarios

• Data availability• Scalability

• Data only available to App

• Data available to multiple solutions

• Data available cross Apps / Solutions

• Data transition• Transforming data to another format

• Move data to specific location

Page 5: Develop business apps   cross-platform development using visual studio with xamarin and azure

Ask yourself the following questions

• Which platforms do i want to support?

• Which systems does my app connect to?

• How many (active) users do i expect?

• Do i need to read and write data from a data container?

• What is the data connectivity for my users?

• Are other systems doing something with my data?

Page 6: Develop business apps   cross-platform development using visual studio with xamarin and azure

Type of Business Apps

• Office Platform• Office Apps• SharePoint hosted Apps, Provider-hosted Apps

• Cloud• Office 365 Apps• Azure Apps

• Windows• Universal Apps• Windows Phone Apps

• Other platforms• Android Apps• iOS Apps

Page 7: Develop business apps   cross-platform development using visual studio with xamarin and azure

DevelopmentCross-platform

• Xamarin Platform

• Xamarin.Forms

• Development

• .NET Libraries

• Models

Page 8: Develop business apps   cross-platform development using visual studio with xamarin and azure

Xamarin Platform

• A platform which allows you to share code accross all platforms witha single shared c# codebase

• Use the same language, APIs and data structures on every platform

• Platforms• iOS, Android, Windows Phone, Windows, Mac

• Xamarin Apps• Standard native user interface controls

• Compiled for native performance

• Leverage hardware acceleration

Page 9: Develop business apps   cross-platform development using visual studio with xamarin and azure

Xamarin tools

• Xamarin platform

• Xamarin Studio• iPhone and Android App development on Mac

• Android App development on Windows PC

• Visual Studio with Xamarin libraries• Windows Phone App development

• Android App development

• Mac and iPhone development only possible in combination with a Mac running XCode and Xamarin Studio, connected by network with theWindows PC

Page 10: Develop business apps   cross-platform development using visual studio with xamarin and azure

Devices & Emulators

• On screen emulators

• Real Phone (connection via USB cable)

Advantages Disavantages

Device • Easier to test

complex touch

interaction

• Feel for startup

and response

time

• Unlocking your Windows Phone

• Need of a developer account

• Android needs to have

debugging enabled

Emulator • Easier to test for

a variety of sizes

and forms

• Android emulators are very

slow

• Mac desktops don’t have touch.

Therefore difficult with controls

Page 11: Develop business apps   cross-platform development using visual studio with xamarin and azure

Xamarin development

Development Tools Language Platform

iOS XCode Objective-C Mac

Android Eclipse Java Lots of platforms

Windows Phone Visual Studio C# Windows PC

• Each language incorporates same sort methods or properties• Example toggle between to states

• iPhone its a view called UISwitch

• Android its a widget called Switch

• Windows Phone its a control called ToggleSwitchButton

• All languages are object-oriented descendants of C

Page 12: Develop business apps   cross-platform development using visual studio with xamarin and azure

Xamarin Platform .NET Libraries

Platform .NET Library Name

iOS Xamarin.iOS MonoTouch

Mac Xamarin.Mac MonoMac

Android Xamarin.Android Mono for Android

These libraries are known as the Xamarin Platform. They containnative Mac, iOS and Android APIs.

Page 13: Develop business apps   cross-platform development using visual studio with xamarin and azure

Shared code

• The trick is the ability of sharing code among the applications

• Platform independent code is isolated by moving it to a separate project

• The project is shared and referenced accross the other platform dependentprojects

• MVVM used in Xamarin projects• Model (underlaying data), View (user interface, visuals and input), ViewModel (manage

data between Model and View)

Page 14: Develop business apps   cross-platform development using visual studio with xamarin and azure

Shared code – can be complicated

• Different platforms use a different subset of the .NET Base Class Library (BCL)

• Different platforms are built to a different .NET Core Library Profile

• When creating cross-platform solutions, each platform can onlyuse class libraries that are targetedto the same profile within thatsolution

Page 15: Develop business apps   cross-platform development using visual studio with xamarin and azure

Shared code - Strategy

Approaches Overview

Shared Asset

Project (SAP)

• Organize your source

code

• Use #if compiler

directives to manage

platform specific

requirements

Portable

Class Library

(PCL)

• Class library targeting

the platforms you

want to support

• Use interfaces to

provide platform

specific functionality

Page 16: Develop business apps   cross-platform development using visual studio with xamarin and azure

Shared code - Shared Asset Project

• Benefits• Simplest approach

• The common code lives in the Shared Asset Project

• All platform projects are sharing the same code

• Branching possible to use compiler redirectives

• Application projects can include platform specificreferences that the shared code can utilize

• Disavantages• No output assembly

• During compilation the files are treated as part of the referencing project. Code is not shared aftercompilation

• Refactorings inside code in “inactive” compiler directives will not update the code

• Code is not intendend for distributing to otherdevelopers

Page 17: Develop business apps   cross-platform development using visual studio with xamarin and azure

Shared code - Portable Class Library

• Benefits• Allows you to share code across multiple

projects

• Refactoring always update all effectedreferences

• The output of the shared code is a class library

• Allows you to share your code with otherdevelopers

• Disavantages• More difficult to implement. You need to

considerate the options

• You can’t use compiler directives

• Only a subset of the .NET framework is available to use, determined by the profile selected

Page 18: Develop business apps   cross-platform development using visual studio with xamarin and azure

Xamarin App development model

iPhone App

Xamarin.iOS

iPhone API

Android App

Xamarin.Android

Android API

Windows Phone App

Windows Phone API

Shared Asset Project or Portable Class Library

Solution with

C# projects

Page 19: Develop business apps   cross-platform development using visual studio with xamarin and azure

Xamarin.Forms - Apps

• Xamarin.Forms• Introduced on may 28th, 2014• Write user-interface code for all platforms at once

• Xamarin.Forms application• 3 platform projects• 1 shared code project

• The shared code project contains most of the application

• The platform projects contains mostly stubs

• Xamarin.Forms Framework• Xamarin.Forms.Core• Xamarin.Forms.Xaml

• Xamarin.Forms is based on MVVM

Page 20: Develop business apps   cross-platform development using visual studio with xamarin and azure

Xamarin.Forms - App development model

iPhone App

Xamarin.iOS

iPhone API

Android App

Xamarin.Android

Android API

Windows Phone App

Windows Phone API

Shared Asset Project or Portable Class Library

Solution with

C# projects

Xamarin.Forms.Core / Xamarin.Forms.Xaml

Page 21: Develop business apps   cross-platform development using visual studio with xamarin and azure

Xamarin.Forms - Example

• Example displays a switch on all three platforms with a single XAML file

Page 22: Develop business apps   cross-platform development using visual studio with xamarin and azure

Xamarin APIs

• http://api.xamarin.com

• You will find here:• Base Class Library

• MonoMac Framework

• Xamarin.Android Framework

• Xamarin.iOS Framework

• Xamarin.Forms

• Other APIs found here from other Xamarin products

Page 23: Develop business apps   cross-platform development using visual studio with xamarin and azure

DEMOFormsGallery

Page 24: Develop business apps   cross-platform development using visual studio with xamarin and azure

Demo – Run the project

Page 25: Develop business apps   cross-platform development using visual studio with xamarin and azure

Programming skills

• Asynchronous programming

• Retrieve data from SharePoint

• Model – View - ViewModel

Page 26: Develop business apps   cross-platform development using visual studio with xamarin and azure

Programming skills – asynchronous

• Working with mobile applications that interact with network, database, files and device hardware reading are much more slower than in normal conditions due to communication bottlenecks

• Asynchronous allows us to run delayed tasks in the background• The program itself can continue without holding up by some task

• Available with .NET Framework 4.5 or higher

• A new simplified approach for running asynchronous tasks

• .NET APIs contain classes supporting asynchronous methods and properties to improve responsiveness

• The task has a state (Running, Finished or Cancelled), a result and is able to throw exceptions

Page 27: Develop business apps   cross-platform development using visual studio with xamarin and azure

Programming skills – asynchronous

• Keywords• async let the compiler know that

the method needs to be handled separately

• await Let the compiler know the suspension of the relative running async task

• Return types• Task or Task<TResult>• Task is used when the method has no

return statement of does not return an operand

Page 28: Develop business apps   cross-platform development using visual studio with xamarin and azure

What happens?

1. Function is called

2. Calls an async method on the object

3. Something causes a delay. It yields control to its caller.

4. The method continues because its not awaited

5. The method is executed synchronous

6. No work further. It now awaits on the result of the asynchronous call

7. The method completes and returns the result.

8. It calculates the length and returns it

Page 29: Develop business apps   cross-platform development using visual studio with xamarin and azure

Retrieve data from SharePoint

• Use WebClient with authentication credentials using SharePointOnlineCredentials()

• JSON as result

• Example: Jtoken listItems = GetList(new Uri(https://appztekonline-public.sharepoint.com”), Credentials(), “B

• If called from an Azure Service you will need to configure some additional settings• Allowed Origins

• Other

Page 30: Develop business apps   cross-platform development using visual studio with xamarin and azure

Model – View - ViewModel

• A model which allows you to create shared code projects at ease

• Model (business logic and underlaying data)

• View (presentation, user interface, visuals and input)

• ViewModel (presentation logic, manage data between Model and View)

Page 31: Develop business apps   cross-platform development using visual studio with xamarin and azure

Development environment

• Software installation

• Development setup

• Android specific• Android API levels

• Android Virtual Device

Page 32: Develop business apps   cross-platform development using visual studio with xamarin and azure

Dev environment – Software installation

• Windows 8 or higher

• Hyper-V enabled• Needed for emulators (Windows Phone, Android)

• Visual Studio 2013 with Update 4• Contains the Windows Phone SDK

• Xamarin for Windows

• Xamarin Android Player for Windows• Only when you want to develop for Android!!• You will need VirtualBox (not possible with Hyper-V enabled)

• Update the Android SDK Manager

Page 33: Develop business apps   cross-platform development using visual studio with xamarin and azure

Dev environment – Development setup

• Create a blank Xamarin App based on Xamarin.Forms Shared

• Remove the iOS project• Mac platform needed and not present (in this case)

• Use Android Virtual Device Manager• Create or use device definitions• Create Android virtual devices based on device definitions

• Project properties of the Android project• Define compile level• Define minimum target level• Define Android version

Page 34: Develop business apps   cross-platform development using visual studio with xamarin and azure

Dev environment - Android API Levels

• API Level determines for which Android versions you can deploy

• Choose the API Level• Install the SDK platform for that level

• Install the system images for that level

• Sources and samples of SDK are available

Page 35: Develop business apps   cross-platform development using visual studio with xamarin and azure

Dev environment - Android Virtual Device

• Create Android Virtual Device• Choose Device

• Choose target (API Level need to be installed)

• CPU/ABI

• In some cases you need to restart Visual Studio to get the device listed under the start button

Page 36: Develop business apps   cross-platform development using visual studio with xamarin and azure

DEMOConfiguration

Page 37: Develop business apps   cross-platform development using visual studio with xamarin and azure

Demo - Configuration

Page 38: Develop business apps   cross-platform development using visual studio with xamarin and azure

Windows Azure

• Why Azure?

• Xamarin and Azure

• Azure Mobile Services

• Azure Messaging component

• Azure Active Directory authentication

Page 39: Develop business apps   cross-platform development using visual studio with xamarin and azure

Why Azure?

• Set of great tools completely integrated with Xamarin• Azure Mobile Service• Push notifications

• All the benefits of a great platform• Scalability• Uniform platform and layer in your solution

• Data synchronization• Asynchronous• Offline data synchronization

• Authentication with Active Directory

Page 40: Develop business apps   cross-platform development using visual studio with xamarin and azure

Xamarin and Azure

• Microsoft Azure plugs easily into Xamarin projects

• Incorporates Azure features like;• Cloud data storage

• Cross-platform push notifications

• Xamarin has components available to integratie it!• Azure Messaging component

Page 41: Develop business apps   cross-platform development using visual studio with xamarin and azure

Azure Mobile Services

• Add structured storage, authentication, push notifications and more toyour Xamarin based mobile application using Microsoft Azure Mobile Services.

• https://components.xamarin.com/view/azure-mobile-services/

Page 42: Develop business apps   cross-platform development using visual studio with xamarin and azure

Azure Messaging component

• Send push notifications to your iOS, Android and Windows apps

• Allows you to register with Azure Notification Hubs

• Send notifications from any backend

• Target content to specific user segments

• Use templates to tailor notifications

• Due to the notification hubs you can scale op to millions of devices and billions of push notifications

• http://components.xamarin.com/view/azure-messaging

Page 43: Develop business apps   cross-platform development using visual studio with xamarin and azure

Azure Active Directory Authentication

• Use Active Directory to authenticate users in Xamarin mobile applications

• Use the same organizational account that employees use to sign in to their corporate environment

• Secure resources like;• Files, links, Web APIs, Office 365 and more

Page 44: Develop business apps   cross-platform development using visual studio with xamarin and azure

Azure Active Directory Authentication

• Get it up and running in three steps• Register with Azure Active Directory

• https://www.windowsazure.com

• Configure Service Access for Mobile Application• http://developer.xamarin.com/guides/cross-

platform/azure/active-directory/

• Develop mobile apps using the service access

• Examples of services you can access include:• Graph API, Web API and Office 365

Page 45: Develop business apps   cross-platform development using visual studio with xamarin and azure

DEMOTodo list with data in Azure

Page 46: Develop business apps   cross-platform development using visual studio with xamarin and azure

Demo – Create mobile service

Page 47: Develop business apps   cross-platform development using visual studio with xamarin and azure

Demo – Get project

Page 48: Develop business apps   cross-platform development using visual studio with xamarin and azure

Demo – Run the project

Page 49: Develop business apps   cross-platform development using visual studio with xamarin and azure

Known issues

• Fastdev directory creation failed

Page 50: Develop business apps   cross-platform development using visual studio with xamarin and azure

Known issues

Issue FastDev directory creation failed

Resolutions Turn off Fast Deployment in project properties

Page 51: Develop business apps   cross-platform development using visual studio with xamarin and azure

Takeaways & Roundup

Page 52: Develop business apps   cross-platform development using visual studio with xamarin and azure

Takeways & Roundup

• The Xamarin platform is great for developing cross-platform business apps

• Understand the technology of Shared Code, choose wisely!

• Not everything is cross-platform. Specific functionality demands written code per platform

• Get to know asynchronous programming with async and await

• The Azure platform is great for expanding your app with storage, push notifications and security

• Integration between Xamarin and Azure

Page 53: Develop business apps   cross-platform development using visual studio with xamarin and azure

Resources

Page 54: Develop business apps   cross-platform development using visual studio with xamarin and azure

Sources & Resources

• Free e-book “Creating Mobile Apps with Xamarin.Forms” by Charles Petzoldhttp://blogs.msdn.com/b/microsoft_press/archive/2014/10/06/free-ebook-creating-mobile-apps-with-xamarin-forms-preview-edition.aspx

• Xamarin platformhttp://xamarin.com/platform

• Xamarin + Azurehttp://developer.xamarin.com/guides/cross-platform/windows/microsoft-azure/

• Xamarin API documentationhttp://api.xamarin.com/

• Xamarin FormsGallery demo – Great impression of the Xamarin.Formshttp://developer.xamarin.com/samples/xamarin-forms/FormsGallery/

• Xamarin early preview setup – Windows Phone 8.1 developmenthttp://developer.xamarin.com/guides/cross-platform/xamarin-forms/windows/installation/

• Managing your Azure environmenthttps://manage.azure.com

Page 55: Develop business apps   cross-platform development using visual studio with xamarin and azure

Questions?