introduction to monotouch

42

Upload: jonas-folleso

Post on 28-Jan-2015

107 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Introduction to MonoTouch
Page 2: Introduction to MonoTouch

MONOTOUCH

Easier development of iOS applications using C#

NNUG Bergen

Jonas Follesø

29/02/2012

Page 3: Introduction to MonoTouch

ABOUT ME

Scientist & Manager BEKK Trondheim

Jonas Follesø

Page 4: Introduction to MonoTouch

AGENDA

What is MonoTouch?

FizzBuzz Demo + Unit Testing

Buss Schedule Demo

Cross Platform Apps

Xamarin.Mobile + MonoTouch.Dialog

Page 5: Introduction to MonoTouch

What is Mono?

Page 6: Introduction to MonoTouch

WHAT IS MONO?

• Open source implementation of the .NET platform

• 2001: Created to bring Windows applications to Linux

• 2003: Acquired by Novell with Ximian

• Matured at Novell – now a world-class runtime.

Page 7: Introduction to MonoTouch

WHAT IS MONO?

C#

IronRuby

IronPython

Visual Basic

F#

Page 8: Introduction to MonoTouch

C# on iOS(iPhone, iPod Touch, iPad)

Page 9: Introduction to MonoTouch

Commercial Product

399$(Free to run in emulator)

15% discount for NNUG

339$xamarin.com/nnug

Page 10: Introduction to MonoTouch

Demo:FizzBuzz

Page 11: Introduction to MonoTouch

UNIT TESTING MONOTOUCH APPS

• NUnit Lite Runner on device/simulator

• Same NUnit syntax you already know

• Possible to run the same NUnit tests on desktop, iOS and WP7 device

Page 12: Introduction to MonoTouch

Demo: Unit Testing

Page 13: Introduction to MonoTouch

.NET & MONO JIT ENGINE

C#Source Code

MonoJust In Time Compilation

MSIL.NET Bytecode

Memory

Executable Machine Code

Page 14: Introduction to MonoTouch

AHEAD-OF-TIME COMPILATION

• Apple disallows Just-In-Time compilation (JIT)

• Cannot make writable memory executable – enforced by OS

• MonoTouch uses Ahead-of-Time Compilation (AOT)• Generates the native code that JIT would normally

generate

• Links to runtime to create single ARM process capable native binary

Page 15: Introduction to MonoTouch

AHEAD-OF-TIME COMPILATION

MSIL.NET Bytecode

MonoCross Compilation

(mtouch)

Native Code

Mono Runtime

Page 16: Introduction to MonoTouch

Thin layer on top of

Cocoa Touch

Page 17: Introduction to MonoTouch

Same UIComponentsnative look & fell

Page 18: Introduction to MonoTouch

MONOTOUCH APIS

.NET APIs

Native APIs

3rd Party APIs

• mscorlib

• System

• System.Core (LINQ)

• System.Data

• Mono.Data.Sqlite

• System.ServiceModel

• System.Json

• System.Web.Services

• System.Xml

• System.Xml.Linq

• AddressBook

• AudioToolbox

• CoreAnimation

• CoreGraphics

• CoreLocation

• EventKit/EventKitUI

• ExternalAccessory

• GameKit

• MapKit

• NewsstandKit

• StoreKit

• UIKit

• And so on...

• OpenTK

• OpenGL

• OpenAL

• SQLite

• MonoGame

• RestSharp

• Json.NET

• ServiceStack

• Steema TeeChart

• Flurry Analytics

• RedLaser

• And so on...

Page 19: Introduction to MonoTouch

Demo:Buss

Schedule

Page 20: Introduction to MonoTouch

Cross PlatformMobile

Development

Page 21: Introduction to MonoTouch

REUSABLE CODE

Easily Reusable

Reusable with some effort

Not reusable

• Domain Model

• Clients for your REST- and web services

• Data Access Code (SQLite)

• Storage Code (Isolated Storage)

• Business Logic

• Code accessing platform specific components that exist across all platforms

• GPS

• Contacts

• Picture Library

• Accelerometer

• User Interface Code

• Boot Strapping Code

Page 22: Introduction to MonoTouch
Page 23: Introduction to MonoTouch
Page 24: Introduction to MonoTouch
Page 25: Introduction to MonoTouch

CODE REUSE FOR MWC APP

57%

60%

65%

iOS Android WP7• 100% reuse of Core Library (1635 LOC)

• iPhone + iPad (2476 LOC)

• Android (1095 LOC)

• WP7 (896 LOC)

Page 26: Introduction to MonoTouch

COMMON API FOR SHARED FUNCTIONALITY

Xamarin.Mobile

Contacts GeolocationCompass +

Accelerometer

CameraNotification

s

Page 27: Introduction to MonoTouch

XAMARIN.MEDIA.MEDIAPICKER

ImageView image = FindViewById<ImageView> (Resource.Id.image);

var picker = new MediaPicker (this);picker.PickPhotoAsync()

.ContinueWith (t => {

            if (t.IsCanceled || t.IsFaulted) // user canceled or errorreturn;

            Bitmap b = BitmapFactory.DecodeFile (t.Result.Path);            RunOnUiThread (() => image.SetImageBitmap (b));

      });

Page 28: Introduction to MonoTouch

XAMARIN.MEDIA.MEDIAPICKER

Page 29: Introduction to MonoTouch

Demo:Xamarin.Mobile

Page 30: Introduction to MonoTouch

Create UI faster using

MonoTouch.Dialog

Page 31: Introduction to MonoTouch

GREATLY SIMPLIFIES CREATION OF SIMPLE UIS

Page 32: Introduction to MonoTouch

TWO APIS: ELEMENTS API

• MonoTouch.Dialog is a framework that brings declarative UI programming to iOS

return new RootElement ("Settings") {

new Section (){

new BooleanElement ("Airplane Mode", false),

new RootElement ("Notifications", 0, 0) {

new Section (null,

"Turn off Notifications to disable Sounds\n" +

"Alerts and Home Screen Badges for the\napplications below."){

new BooleanElement ("Notifications", false)

}

}},

Page 33: Introduction to MonoTouch

TWO APIS – REFLECTION API

class AccountInfo { [Section] public bool AirplaneMode;

[Section ("Data Entry", "Your credentials")]

[Entry ("Enter your login name")] public string Login;

[Caption ("Password"), Password ("Enter your password")] public string passwd;

[Section ("Travel options")] public SeatPreference preference;}

Page 34: Introduction to MonoTouch

Demo:MonoTouch.Dialog

Page 35: Introduction to MonoTouch

Is it readyfor business?

Page 36: Introduction to MonoTouch

CONTROVERSY 1: APRIL 2010 – APPLE’S SECTION 3.3.1

• April 8nd: Apple changed license to state that:

“Applications must be originally written in Objective-C, C, C++, or JavaScript as executed by the iPhone OS WebKit engine, and only code written in C, C++, and Objective-C may compile and directly link against the Documented APIs…”

• September 9th: Apple changed license again:

“In particular, we are relaxing all restrictions on the development tools used to create iOS apps, as long as the resulting apps do not download any code. This should give developers the flexibility they want, while preserving the security we need.”

Page 37: Introduction to MonoTouch

CONTROVERSY 2: MAY 2011 - ATTACHEMATE

• May 2nd: Attachemate buys Novell – Mono team laid off

• Xamarin founded 2 weeks later

• Angry Mono customers pressure Novell to cooperate with Xamarin

• Xamarin secures a perpetual license to all Mono IP: copyrights, patents and trademarks

Page 38: Introduction to MonoTouch

Basically:All good!

Page 39: Introduction to MonoTouch

MONOTOUCH & iOS RELEASE HISTORY

2009.09.14MT v1.0

2010.04.05 MT v2.0(iPad) 2011.04.06

MT v4.02011.10.12

MT v5.02012.01.17MT v5.2.5

2009.07.17iOS v3.0

2010.04.03iOS v3.2

(iPad)

2010.06.21iOS v4.0

2010.04.05 MT v3.0

(iPhone 4)

2010.06.21iOS v4.0

2011.10.12iOS v5.0

Page 40: Introduction to MonoTouch

Summary

Page 41: Introduction to MonoTouch

SUMMARY

C# for iOS

Cross Platform

Useful resources

• Makes iOS easily accessible for .NET developers.

• Thin layer on top of CocoaTouch – same native look & feel

• MonoTouch.Dialog for easier UI creation

• Standard .NET libraries for tasks such as:

• File Access

• Database Access

• Web Service Access

• Business Logic

• Xamarin.Mobile provides same API for common phone functionality

• NDC 2011 presentation on cross platform mobile: http://vimeo.com/26701639

• http://xamarin.com/NNUG for 15% discount on MonoTouch & Mono for Android

• https://github.com/follesoe/FlightsNorway/tree/workshop for 50 page workshop on cross platform development using Mono.

Page 42: Introduction to MonoTouch

Questions?