Italian Alt.Net Conference MonoTouch Session
-
Upload
chris-hardy -
Category
Technology
-
view
1.725 -
download
0
description
Transcript of Italian Alt.Net Conference MonoTouch Session
![Page 1: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/1.jpg)
C# on the iPhonewith MonoTouch
Chris Hardy@chrisntr
![Page 3: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/3.jpg)
Covering...
• What is MonoTouch?
• How does it work?
• Why would you use it?
• Demos
![Page 4: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/4.jpg)
Starting point....
![Page 5: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/5.jpg)
Objective C and Xcode
![Page 6: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/6.jpg)
Learn to read Objective-C
![Page 7: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/7.jpg)
Learn to read Objective-C
• All Apple documentation is in Obj-C
• Most examples are in Obj-C
• It’s not too hard to understand
• It might even be fun...
![Page 8: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/8.jpg)
What is MonoTouch?
![Page 9: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/9.jpg)
What is Mono?
![Page 10: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/10.jpg)
What is Mono?
Open Source .Net Implementation of the
Microsoft .Net Framework
![Page 11: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/11.jpg)
Mono’s JIT Engine
CIL
Mono
Memory
![Page 12: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/12.jpg)
Apple No No...
• Contractual Requirements
• No interpreted code
• No shared libraries
• Kernel Limitations
• iPhone OS 2.0+ disables JIT
![Page 13: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/13.jpg)
Mono’s AOT Engine
CIL
Mono
AOTMono Runtime
ARM
Native Code
![Page 14: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/14.jpg)
Monotouch Features• mtouch• MonoDevelop iPhone Add-In• CocoaTouch.NET• Full static AOT compiler• Support for all your existing code• Reflection• Generics• LINQ• Anonymous Methods• Lambda’s etc...
![Page 15: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/15.jpg)
MonoTouch’s APIs
![Page 16: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/16.jpg)
The Bindings• MonoTouch namespace
• MonoTouch.Foo namespace
• Maps to CocoaTouch’s Foo Framework
• 1:1 Mapping of classes.
• MonoTouch.UIKit.UILabel
• CocoaTouch’s UIKit framework, UILabel class
![Page 17: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/17.jpg)
Strong Types
• Objective-C
• Arrays are weakly typed:• NSArray return values.
• MonoTouch has strong types
• UIView[] Subviews { get; }• vs• NSArray *subviews;
• Intellisense - explore the API...
![Page 18: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/18.jpg)
Garbage Collection• Automatic:
• Mono’s GC will collect objects on demand
• Deterministic:
• Use when you need control.
• Every object in MonoTouch implements IDisposable
using (var image = UIImage.FromFile(“foo.png”)){
surface.DrawImage(image, 20, 20);
}
![Page 19: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/19.jpg)
Linker
![Page 20: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/20.jpg)
What about App Size?
• 10 MB (compressed) limit on 3G/Edge downloads
• .Net BCL and other libraries are huge
• Mono Linker to the rescue!
![Page 21: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/21.jpg)
Linking Assemblies
![Page 22: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/22.jpg)
Linker Options
• No Link
• Link SDK Only
• Full Link
![Page 23: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/23.jpg)
Pipeline
• Interface Builder GUI Designer
• Exact same tool used by Xcode
• Support for existing Xcode interfaces
• MonoDevelop IDE
![Page 24: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/24.jpg)
Integration
• Tight integration between MD and IB
• IB produces XIBs with MD parses
• Automatic class generation in MD
• Generates partial classes for all types, outlets and actions defined in Interface Builder
![Page 25: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/25.jpg)
Outlets
• Instance Variables
• Can be strong or loosely typed
• MD will strong type
![Page 26: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/26.jpg)
Actions
• Objects emit broadcast messages to receivers
• You can do this C#
• MonoDevelop takes care of the details for you
• Creates partial methods for you extend
![Page 27: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/27.jpg)
MonoTouch Events
• Supports Objective-C pattern:
webView.Delegate = new MyWebViewDelegate();
• C# style events as well:
webView.PageLoaded += delegate {HideSpinningWheel();
}
![Page 28: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/28.jpg)
Debugging
• Console.WriteLine(“Debugging inside of MonoTouch”);
• printf(“I made it to this line!\n”)
![Page 29: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/29.jpg)
Well...
• MonoTouch released around 15th September 2009
• MonoTouch 1.1 on 2nd October 2009
• MonoTouch 1.2 (Beta) released on 28th October 2009... With Debugging support
• Currently on MonoTouch 1.4.5
![Page 30: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/30.jpg)
Debugger
• MonoTouch debugger leverages Mono’s new Soft-Debugger
• Supports the Simulator
• Supports the Device...
• even over WiFi
![Page 31: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/31.jpg)
Debugger Features• Breakpoints
• Catchpoints
• Inspection
• Watches
• Immediate / Expression Evaluator
• Call Stack
• Stepping
![Page 32: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/32.jpg)
Caveats
• Debug binaries on devices are very large
• Cannot debug Main or FinishedLaunching on device
• Consumes more memory runtime
• Performance hit
![Page 33: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/33.jpg)
Getting started
• Get iPhone SDK from Apple
• Get Mono from Novell
• Get MonoTouch (evaluation version is free)
• Get MonoDevelop
• Register with Apple iPhone Developer Program and purchase MonoTouch for putting apps on device and AppStore.
![Page 34: Italian Alt.Net Conference MonoTouch Session](https://reader033.fdocuments.us/reader033/viewer/2022060115/557ad604d8b42add288b527d/html5/thumbnails/34.jpg)
Demo time...