34

Developing i phone, android and windows phone 7 applications with c#

Embed Size (px)

DESCRIPTION

Session presented at Microsoft Techdays, see the video here:http://channel9.msdn.com/Events/TechDays/Techdays-2012-the-Netherlands/2143

Citation preview

Page 1: Developing i phone, android and windows phone 7 applications with c#
Page 2: Developing i phone, android and windows phone 7 applications with c#

Developing iPhone, Android and Windows Phone 7 applications with C#

Roy CornelissenIT Architect,Info Support

Willem MeintsDeveloper,Info Support

Roy CornelissenIT ArchitectInfo Support

Willem MeintsDeveloperInfo Support

Marcel de VriesTechnology ManagerInfo Support

Page 3: Developing i phone, android and windows phone 7 applications with c#

Patterns ProofAgenda

Myths ALM

Page 4: Developing i phone, android and windows phone 7 applications with c#

Setting the context

Windows PhoneVisual Studio, XAML and C#

iOSMonoDevelop, MonoTouch and C#

AndroidVisual Studio, Mono for Android and C#C#

Page 5: Developing i phone, android and windows phone 7 applications with c#

Myth Busters

Common misconceptions

Page 6: Developing i phone, android and windows phone 7 applications with c#

Myth: Apps built with C# are not native

Page 7: Developing i phone, android and windows phone 7 applications with c#

C / C++Different CPU architectures

What is the meaning of “native”?• Different interpretations of “native”

Java

Objective-CC / C++

C# / Silverlight 3+

Page 8: Developing i phone, android and windows phone 7 applications with c#

What is the meaning of “native”?

• Native = use the frameworks and libraries of the OS, regardless of the language or tools• Native = User experience 100% aligned with default OS device experience

Page 9: Developing i phone, android and windows phone 7 applications with c#

DemoKnowledge Events app

Page 10: Developing i phone, android and windows phone 7 applications with c#

3 native flavors

App Logic

Vendor tools “Magic Box” Hybrid

XCodeObjective-

C

WP7 Silverligh

tC#

Android SDKJava

Appcelerator Titanium

JavaScript > Native

PhoneGapHTML5 / CSS /

JS

Adobe AIRActionScript

AntennaRapid

Scripting Language

Service2Media

Lua

C#

Xamarin

MonoTouch

WP7 Silverlig

ht XamarinMono for Android

RhodesRuby + HTML

Sybase Unwired

“4GL” code gen Shared

language

Page 11: Developing i phone, android and windows phone 7 applications with c#

Myth: Applications written with Mono are slow

Page 12: Developing i phone, android and windows phone 7 applications with c#

Demo: Mandelbrot comparison

Text/Icon/PicMonoTouch

Objective-CText/Icon/Pic

Benoit Mandelbrot

Page 13: Developing i phone, android and windows phone 7 applications with c#

Comparison Mono & Objective-C / Java

Speed upyour app

Develop wisely!

1.0

1.0

Application startup

Compute intensive

Service calls

UI interaction

Page 14: Developing i phone, android and windows phone 7 applications with c#

Perceived performanceYes there is overheadNative-to-Managed causes overheadMono has a garbage collectorCPU-intensive: use LLVM compiler

But it’s no problemMost of us don’t build real time 3D gfx

Make the app feel fastKeep download size smallCut startup time by offloading tasks ASAPUse background tasks & activity indicators

…is in the eye of the beholder

Performance…

Page 15: Developing i phone, android and windows phone 7 applications with c#

Even game developers choose Mono!

Delta engine

Page 16: Developing i phone, android and windows phone 7 applications with c#

Myth: Mono cannot access all device capabilities

Page 17: Developing i phone, android and windows phone 7 applications with c#

You can access all device capabilities!• For each platform there is a set of namespaces that

enable full device accessiOS

MonoTouch.CoreLocationMonoTouch.CoreMotionMonoTouch.AVFoundationMonoTouch.AddressBookMonoTouch.EventKit…

Android: Android.Hardware.SensorAndroid.LocationAndroid.BluetoothAndroid.Nfc…

Windows Phone: Microsoft.Devices.Sensors.GyroscopeMicrosoft.Devices.Sensors.AccelerometerMicrosoft.Devices.Sensors.CompassMicrosoft.Devices.Sensors.Motion…

Use device abstractions!

Page 18: Developing i phone, android and windows phone 7 applications with c#

Myth: Code Sharing percentage between apps is very low because of the different implementations per device

Page 19: Developing i phone, android and windows phone 7 applications with c#

Code Sharing

Reusable20%

Shared app logic20%Windows8

13%

iOS18%

WP712%

Android16%

Shared

65%

Specific35%

Per App

Page 20: Developing i phone, android and windows phone 7 applications with c#

More on this later

As long as you do proper design

Page 21: Developing i phone, android and windows phone 7 applications with c#

Myth: You do not have to know the different devices to build apps for all different platforms

Roy Cornelissen

Willem Meints

Marcel de Vries

Page 22: Developing i phone, android and windows phone 7 applications with c#

Application Lifecycle Management

Managing cross platform development

Page 23: Developing i phone, android and windows phone 7 applications with c#

Cross device solution setup

Same directory structure used by all solutions

• Shared implementation project

• Include files your project needs

• Exclude files that are device specific

Page 24: Developing i phone, android and windows phone 7 applications with c#

Cross platform version control• Use TFS in the cloud• Use Local Workspaces• SVN model of Edit, Merge, check-in• No need to check out before edit

• Use Team Explorer Everywhere for Mac OS

• Added bonus: full support for Work Items, Build, etc.

Page 25: Developing i phone, android and windows phone 7 applications with c#

Architecture & Design Patterns

How to maximize reuse between platforms

Page 26: Developing i phone, android and windows phone 7 applications with c#

Define architecture for reuse

Page 27: Developing i phone, android and windows phone 7 applications with c#

Define architecture for reuse

Services

Model

ControllerViewModel

Etc.

GPS

Storage

Motion sensors

View

Shared?

BridgeShared Platform specific

Page 28: Developing i phone, android and windows phone 7 applications with c#

Services• What technology do you use to access data?• Should we use REST/WebApi?• Lot of hand coding since there is no standard way to generate

proxies• Should we do SOAP?• Good option, also provides out of the box support in the tools for

proxy generation• Proxy generation with SL tools, so we have full shared code base

cross stacks

• Use RIA services as back-end• Adds productivity for back-end and flexibility in endpoints• SOAP, JSON, OData

Page 29: Developing i phone, android and windows phone 7 applications with c#

Callback pattern

Shared Controller

UIViewController

XAML View Activity

Web Services

SF

SF

SF

Model

GetActualEvents (Action<object> OnSuccess,

Action<Exception> OnFail)

PropertyChanged(“Events”);

public void OnFailed(Exception e){ // Do something with error}

public void OnSuccess(object data){ // Do something with data // Notify user}

Page 30: Developing i phone, android and windows phone 7 applications with c#

Device Abstraction Patterns

Page 31: Developing i phone, android and windows phone 7 applications with c#

The proof of the pudding is in the eating…

Page 32: Developing i phone, android and windows phone 7 applications with c#

DemoBuilding an Event app

Page 33: Developing i phone, android and windows phone 7 applications with c#

Lessons learned• Android == Wild Wild West of mobile• Test ALWAYS on MULTIPLE devices!• Mono Release cycle only small lag with

vendor tools• UX design essential for apps• Good design up front of the app essential for

code sharing• First attempt 10% code share • Now we achieve 70-80% code sharing!

Page 34: Developing i phone, android and windows phone 7 applications with c#

© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Roy Cornelissen@roycornelissen

Willem Meints@wmeints

Marcel de Vries@marcelv