Cross-platform mobile dev with Mono


Published on

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

Published in: Technology
1 Comment
1 Like
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • These examples are useful
  • These examples are useful
  • Cross-platform mobile dev with Mono

    1. 1. Multi-platform with Mono
    2. 4. iOS Basics <ul><li>Based on Mac OSX – so it's Unix </li></ul><ul><li>Development is done with Objective-C </li></ul><ul><ul><li>No memory management (on iOS devices) </li></ul></ul><ul><ul><li>Some 'different' syntax [[Fraction alloc] init] </li></ul></ul><ul><ul><li>but readable for c# developers, particularly once you get your head around message-passing, protocols, delegates and their MVC interpretation </li></ul></ul>
    3. 5. Android Basics <ul><li>Based on Linux 2.6 – so it's Unix </li></ul><ul><li>Development is done with Java </li></ul><ul><ul><li>“ Every Android application runs in its own process, with its own instance of the Dalvik virtual machine” </li></ul></ul><ul><ul><li>very readable for c# developers, so existing examples and documentation are accessible </li></ul></ul>
    4. 6. What is Mono? <ul><li>Open source implementation of the CLR </li></ul><ul><ul><li>Linux, MacOS X, Solaris, BSD, Wii, PS3 </li></ul></ul><ul><ul><li>Started in 2001, purchased by Novell in 2003, released in 2004 </li></ul></ul><ul><li>'binary compatible' with Microsoft .NET </li></ul><ul><ul><li>Existing .NET assemblies will run </li></ul></ul><ul><ul><li>Includes the framework </li></ul></ul><ul><li> </li></ul><ul><li> </li></ul>
    5. 7. What is MonoTouch? Mono ('Silverlight subset') + iOS API bindings + Xcode/Interface Builder parser + Static (AOT) compiler = Native iPhone/iPad application Released Sept 2009
    6. 8. MonoTouch System Req's <ul><li>To play in the simulator ( FREE ) </li></ul><ul><ul><li>Intel-based Mac OSX (latest : Snow Leopard) </li></ul></ul><ul><ul><li>Apple's iPhone SDK (Simulator) ^ </li></ul></ul><ul><ul><li>Mono for OSX </li></ul></ul><ul><ul><li>MonoTouch Trial (and MonoDevelop IDE) ^ </li></ul></ul><ul><li>To get onto your iPhone/iPad (and into the AppStore) </li></ul><ul><ul><li>Apple Developer Program membership (USD99) ^ </li></ul></ul><ul><ul><li>MonoTouch Prof or Enterprise license (USD399+) </li></ul></ul>
    7. 9. What is Mono for Android? Mono ('Silverlight subset') + Android API bindings + 'AXML' intellisense support + Visual Studio plug-in (or MonoDevelop) = Android application Released April 2011
    8. 10. Mono for Android System Req's <ul><li>To play in the simulator ( FREE ) </li></ul><ul><ul><li>Mac OSX with MonoDevelop OR Windows (VisualStudio 2010 or MonoDevelop) </li></ul></ul><ul><ul><li>Oracle's Java SDK </li></ul></ul><ul><ul><li>Google's Android SDK </li></ul></ul><ul><ul><li>Mono for Android Trial (and MonoDevelop IDE) </li></ul></ul><ul><li>To get onto a device </li></ul><ul><ul><li>Mono for Android Prof or Enterprise license (USD399+) </li></ul></ul><ul><li>To get onto Android Market </li></ul><ul><ul><li>Google Developer account (USD25) </li></ul></ul>
    9. 11. What is Mono for WP7?
    10. 12. 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 :-)
    11. 13. Details! <ul><li>Debugging </li></ul><ul><li>Linking </li></ul><ul><li>UI </li></ul><ul><ul><li>iOS </li></ul></ul><ul><ul><li>Android </li></ul></ul><ul><li>Navigation </li></ul><ul><li>Databinding </li></ul><ul><li>F.A.Q. </li></ul>
    12. 14. Debugging <ul><li>'soft debugger' gets embedded in your app </li></ul><ul><ul><li>Can be configured (IP address, port) </li></ul></ul><ul><ul><li>Binaries are much larger (of course) </li></ul></ul><ul><li>Allows breakpoints, step-through, call stack </li></ul><ul><li>Works via TCP/IP, so you can debug the Simulator AND the device (untethered, so long as wifi is enabled). </li></ul>
    13. 15. Linking <ul><li>Mono compiler strips out unused classes/libraries </li></ul><ul><ul><li>Mobile devices – size matters! </li></ul></ul><ul><ul><li>Trap for young players: it might strip out stuff you want to keep! </li></ul></ul><ul><ul><ul><li>Classes/methods/properties used via Reflection </li></ul></ul></ul><ul><ul><ul><li>Classes/methods/properties used in serialization operations </li></ul></ul></ul><ul><li>By default it's disabled in DEBUG, so stuff will work there and mysteriously break in RELEASE [ Preserve (AllMembers = true )] </li></ul>
    14. 16. Binding to iOS Native Controls 1 <ul><li>MonoTouch.* namespaces 'map' to the native iPhone OS SDK 'frameworks', eg. </li></ul><ul><li>MonoTouch.UIKit contains </li></ul><ul><ul><li>UITableView, UITextBox/UITextBlock, UIButton </li></ul></ul><ul><li>MonoTouch.MapKit contains </li></ul><ul><ul><li>MKMapView, MKUserLocation </li></ul></ul><ul><li>MonoTouch.CoreLocation </li></ul><ul><ul><li>CLLocationCoordinate2D </li></ul></ul><ul><ul><li>etc... </li></ul></ul>
    15. 17. Binding to iOS Native Controls 2 <ul><li>Layouts are generally 'absolute positioned' </li></ul><ul><ul><li>More like Windows Forms </li></ul></ul><ul><ul><li>Views can be nested; custom views can be created </li></ul></ul><ul><ul><li>You may end up 'measuring' text to get tight layouts </li></ul></ul><ul><ul><li>UITableView gets used a LOT </li></ul></ul><ul><li>Two ways to build: </li></ul><ul><ul><li>Xcode / Interface Builder </li></ul></ul><ul><ul><li>Programmatically ← my preference </li></ul></ul>
    16. 18. Interface Builder integration 1 <ul><li>Interface Builder is like the Visual Studio designer for ASPX and XAML – except it creates .XIB files </li></ul>
    17. 19. Interface Builder integration 2 <ul><li>.designer.cs behaves similarly to .NET – detects XIB changes and generates partial classes provide a hook for your GUI controls </li></ul>
    18. 20. Binding to Android Native Controls 1 <ul><li>Android.* namespaces 'map' to the native Android SDK classes, eg. </li></ul><ul><li>Android.Widget contains </li></ul><ul><ul><li>ListView, Button, ImageView, TextView </li></ul></ul><ul><li>Android.App contains </li></ul><ul><ul><li>Activity, Dialog, Application </li></ul></ul><ul><li>etc... </li></ul><ul><li>but some things (eg. Map) still not quite there </li></ul>
    19. 21. Binding to Android Native Controls 2 <ul><li>Layout is generally 'relative' </li></ul><ul><ul><li>More like XAML [LinearLayout ~= StackPanel] </li></ul></ul><ul><ul><li>Doesn't mean things can't overlap! </li></ul></ul><ul><ul><li>Custom views can be created and referenced in your axml (namespace trick) </li></ul></ul><ul><li>Two ways to build: </li></ul><ul><ul><li>axml in the /Layout/ folder ← my preference </li></ul></ul><ul><ul><li>programmatically </li></ul></ul>
    20. 22. Android UI Designer <ul><li>There isn't one! (of the same quality. Options include DroidDraw) </li></ul><ul><li>Resource.Designer.cs </li></ul><ul><ul><li>Intellisense for UI elements (from .axml to c#) </li></ul></ul><ul><ul><li>.axml is used to enable intellisense </li></ul></ul><ul><ul><li>NOT a full partial-class linking axml-Activity * </li></ul></ul><ul><ul><ul><li>FindViewById<T> is used to wire up yourself </li></ul></ul></ul>*
    21. 23. Navigation <ul><li>Getting from screen to screen </li></ul><ul><li>StartActivity() </li></ul><ul><li>Intent </li></ul><ul><ul><li>SetClass typeof(AnActivity) </li></ul></ul><ul><ul><li>PutExtra </li></ul></ul><ul><ul><li>Can also 'trigger' other applications </li></ul></ul><ul><li>PushViewController() </li></ul><ul><li>UIViewController </li></ul><ul><ul><li>Subclass and pass instance </li></ul></ul><ul><li>… also UITabBar items </li></ul>
    22. 24. Databinding (lists) <ul><li>More work that you are used to... </li></ul><ul><li>BaseAdapter </li></ul><ul><ul><li>GetView </li></ul></ul><ul><ul><li>Count </li></ul></ul><ul><ul><li>GetItem </li></ul></ul><ul><ul><li>(.ItemClick is attached to the ListView itself) </li></ul></ul><ul><li>UITableViewSource </li></ul><ul><ul><li>GetCell </li></ul></ul><ul><ul><li>RowsInSection </li></ul></ul><ul><ul><li>RowSelected </li></ul></ul>
    23. 25. 'translation'
    24. 26. F.A.Q. <ul><li>Questions I've been asked in the past: </li></ul><ul><li>Filesystem </li></ul><ul><li>Settings </li></ul><ul><li>Sqlite </li></ul><ul><li>WebClient </li></ul><ul><li>Incoming connections </li></ul><ul><li>Interfacing with the device (call, gps, camera) </li></ul>
    25. 27. Example: RestGuide Runs on Android, iOS and Windows Phone 7
    26. 28. Example: MIX11 Runs on Android, iOS and Windows Phone 7
    27. 29. Any questions?
    28. 30. Professional iPhone w/ MonoTouch