Cross-platform mobile dev with Mono

Post on 15-May-2015

8537 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

Cross-platform mobile development with Mono (MonoTouch & Mono-for-Android). Presentation from 7th May 2011 at Mobile Camp Oz (Bathurst, NSW, Australia)

Transcript

http://conceptdev.blogspot.com

@conceptdev

Multi-platform with Mono

http://conceptdev.blogspot.com

@conceptdev

http://conceptdev.blogspot.com

@conceptdev

http://conceptdev.blogspot.com

@conceptdev

iOS Basics

Based on Mac OSX – so it's Unix Development is done with Objective-C

No memory management (on iOS devices) Some 'different' syntax [[Fraction alloc] init] but readable for c# developers, particularly once you

get your head around message-passing, protocols, delegates and their MVC interpretation

http://conceptdev.blogspot.com

@conceptdev

Android Basics

Based on Linux 2.6 – so it's Unix Development is done with Java

“Every Android application runs in its own process, with its own instance of the Dalvik virtual machine”

very readable for c# developers, so existing examples and documentation are accessible

http://conceptdev.blogspot.com

@conceptdev

What is Mono? Open source implementation of the CLR

Linux, MacOS X, Solaris, BSD, Wii, PS3 Started in 2001, purchased by Novell in 2003,

released in 2004 'binary compatible' with Microsoft .NET

Existing .NET assemblies will run Includes the framework

http://www.mono-project.com/ http://github.com/mono

http://conceptdev.blogspot.com

@conceptdev

What is MonoTouch? Mono ('Silverlight subset')

+ iOS API bindings

+ Xcode/Interface Builder parser

+ Static (AOT) compiler

= Native iPhone/iPad application

http://monotouch.net/

Released Sept 2009

http://conceptdev.blogspot.com

@conceptdev

MonoTouch System Req's To play in the simulator (FREE)

Intel-based Mac OSX (latest : Snow Leopard) Apple's iPhone SDK (Simulator) ^ Mono for OSX MonoTouch Trial (and MonoDevelop IDE) ^

To get onto your iPhone/iPad (and into the AppStore)

Apple Developer Program membership (USD99) ^ MonoTouch Prof or Enterprise license (USD399+)

http://conceptdev.blogspot.com

@conceptdev

What is Mono for Android? Mono ('Silverlight subset')

+ Android API bindings

+ 'AXML' intellisense support

+ Visual Studio plug-in (or MonoDevelop)

= Android application

http://mono-android.net/

Released April 2011

http://conceptdev.blogspot.com

@conceptdev

Mono for Android System Req's To play in the simulator (FREE)

Mac OSX with MonoDevelop OR Windows (VisualStudio 2010 or MonoDevelop)

Oracle's Java SDK Google's Android SDK Mono for Android Trial (and MonoDevelop IDE)

To get onto a device Mono for Android Prof or Enterprise license (USD399+)

To get onto Android Market Google Developer account (USD25)

http://conceptdev.blogspot.com

@conceptdev

What is Mono for WP7?

http://conceptdev.blogspot.com

@conceptdev

What is Mono for WP7? Kidding!

Just grab the Windows Phone 7 Developer Tools (with Visual Studio 2010 Express) and use the real .NET Framework :-)

There will be other sessions about WP7...

just keep in mind that the non-UI code you write there can run on iOS & Android thanks to Mono :-)

http://conceptdev.blogspot.com

@conceptdev

Details! Debugging Linking UI

iOS Android

Navigation Databinding F.A.Q.

http://conceptdev.blogspot.com

@conceptdev

Debugging 'soft debugger' gets embedded in your app

Can be configured (IP address, port) Binaries are much larger (of course)

Allows breakpoints, step-through, call stack Works via TCP/IP, so you can debug the

Simulator AND the device (untethered, so long as wifi is enabled).

http://conceptdev.blogspot.com

@conceptdev

Linking Mono compiler strips out unused classes/libraries

Mobile devices – size matters! Trap for young players: it might strip out stuff you

want to keep! Classes/methods/properties used via Reflection Classes/methods/properties used in serialization operations

By default it's disabled in DEBUG, so stuff will work there and mysteriously break in RELEASE

[Preserve(AllMembers = true)]

http://conceptdev.blogspot.com

@conceptdev

Binding to iOS Native Controls 1

MonoTouch.* namespaces 'map' to the native iPhone OS SDK 'frameworks', eg.

MonoTouch.UIKit contains UITableView, UITextBox/UITextBlock, UIButton

MonoTouch.MapKit contains MKMapView, MKUserLocation

MonoTouch.CoreLocation CLLocationCoordinate2D etc...

http://conceptdev.blogspot.com

@conceptdev

Binding to iOS Native Controls 2 Layouts are generally 'absolute positioned'

More like Windows Forms Views can be nested; custom views can be created You may end up 'measuring' text to get tight layouts UITableView gets used a LOT

Two ways to build: Xcode / Interface Builder Programmatically ← my preference

http://conceptdev.blogspot.com

@conceptdev

Interface Builder integration 1

Interface Builder is like the Visual Studio designer for ASPX and XAML – except it creates .XIB files

http://conceptdev.blogspot.com

@conceptdev

Interface Builder integration 2 .designer.cs behaves similarly to .NET – detects

XIB changes and generates partial classes provide a hook for your GUI controls

http://conceptdev.blogspot.com

@conceptdev

Binding to Android Native Controls 1

Android.* namespaces 'map' to the native Android SDK classes, eg.

Android.Widget contains ListView, Button, ImageView, TextView

Android.App contains Activity, Dialog, Application

etc...

but some things (eg. Map) still not quite there

http://conceptdev.blogspot.com

@conceptdev

Binding to Android Native Controls 2 Layout is generally 'relative'

More like XAML [LinearLayout ~= StackPanel] Doesn't mean things can't overlap! Custom views can be created and referenced in your

axml (namespace trick) Two ways to build:

axml in the /Layout/ folder ← my preference programmatically

http://conceptdev.blogspot.com

@conceptdev

Android UI Designer There isn't one! (of the same quality. Options include DroidDraw)

Resource.Designer.cs Intellisense for UI elements (from .axml to c#) .axml is used to enable intellisense NOT a full partial-class linking axml-Activity *

FindViewById<T> is used to wire up yourself

* http://betasoftware.blogspot.com/2011/02/automated-monodroid-layout-t4-edition.html

http://conceptdev.blogspot.com

@conceptdev

Navigation

Getting from screen to screen

StartActivity() Intent

SetClasstypeof(AnActivity)

PutExtraCan also 'trigger' other

applications

PushViewController() UIViewController

Subclass and pass instance

… also UITabBar items

http://conceptdev.blogspot.com

@conceptdev

Databinding (lists)

More work that you are used to...

BaseAdapter GetView Count GetItem(.ItemClick is attached to the

ListView itself)

UITableViewSource GetCell RowsInSection RowSelected

http://conceptdev.blogspot.com

@conceptdev

'translation'

http://conceptdev.blogspot.com

@conceptdev

F.A.Q.

Questions I've been asked in the past:

Filesystem Settings Sqlite WebClient Incoming connections Interfacing with the device (call, gps, camera)

http://conceptdev.blogspot.com

@conceptdev

Example: RestGuide

Runs on Android, iOS and

Windows Phone 7

github.com/conceptdev

http://conceptdev.blogspot.com

@conceptdev

Example: MIX11

Runs on Android, iOS and

Windows Phone 7

mix11.confapp.com

http://conceptdev.blogspot.com

@conceptdev

Any questions?

http://conceptdev.blogspot.com

@conceptdev

Professional iPhone w/ MonoTouch

top related