MonoTouch andMono for Android         with some Windows Phone 7        NxtGen User Group Cambridge, Shenfield & Southampton...
Chris Hardy• ASPInsider• Write some books• http://twitter.com/chrisntr• Work for great fridays
http://greatfridays.com
http://emmawatson.com
http://dominion-funds.com
Covering...• How these technologies work• Demos• Similarities between MonoTouch and Mono  for Android• Code Re-use with Mo...
MonoTouch
What is Mono?   The .Net Frameworkcreated by Miguel De Icaza           et al.
Miguel de Icaza
What is MonoTouch? C# and .NET on the       iPhone
Demo - Walkthrough
Mono’s JIT Engine             Memory      MonoCIL
Apple Rules• Contractual Requirements • No interpreted code • No shared libraries• Kernel Limitations • iPhone OS 2.0+ dis...
Mono’s AOT Engine             Native             Code      Mono      AOT      Mono RuntimeCIL                        ARM
MonoTouch Features• mtouch• MonoDevelop iPhone Add-In• CocoaTouch.NET / monotouch.dll• Full static AOT compiler• Support f...
MonoTouch’s APIs
Strong Types• Objective-C • Arrays are weakly typed: • NSArray return values.• MonoTouch has strong types • UIView[] Subvi...
MonoTouch Events• Supports Objective-C pattern (including  blocks): webView.Delegate = new MyWebViewDelegate();• C# style ...
Garbage Collection•   Automatic:    •   Mono’s GC will collect objects on demand•   Deterministic:    •   Use when you nee...
MonoTouch Design         Integration• Integrates with Interface Builder and Xcode  3• Xcode 4 support coming
Demo - Integration
Learn to read Objective-C
Learn to read Objective-C • All Apple documentation is in Obj-C • Most examples are in Obj-C • It’s not too hard to unders...
The Bindings• MonoTouch namespace• MonoTouch.Foo namespace • Maps to CocoaTouch’s Foo Framework• 1:1 Mapping of classes. •...
Binding against 3rd   party libraries• https://github.com/chrisntr/monotouch-  bindings/tree/master/BingMaps• Demo showing...
Who’s using          MonoTouch?• Medtronic - http://www.apple.com/ipad/  business/profiles/medtronic/• iCircuit - http://it...
Getting started• Get iPhone SDK from Apple• Get Mono from Novell• Get MonoTouch (evaluation version is free)• Get MonoDeve...
DemoTwitter on iPhone with MonoTouch
What is Mono for   Android?
What is MonoDroid? C# and .NET on    Android
Demo
How does MonoDroid      work?
What is MonoDroid?  Cross-platform
MonoDroid Features• mandroid.exe• Visual Studio 2010 Integration• MonoDevelop MonoDroid Add-In• Mono.Android.dll• Full sta...
What is MonoDroid?v1.0 released in March  was expected late       2010...
What is MonoDroid?Expect rapid releases a    la MonoTouch
What is MonoDroid?A commercial product   same prices as    MonoTouch
What is MonoDroid?  Give feedback!   Submit bugs! http://monodroid.net/
Mono for Android  book on its way!Out around   July
DemoTwitter on Android with MonoDroid
Similarities withMonoTouch and  MonoDroid
Linkerand the application size...
What about App Size?• 20 MB (compressed) limit on 3G/Edge  downloads• .Net BCL and other libraries are huge• Mono Linker t...
Linking Assemblies
Linker Options• No Link• Link SDK Only• Full Link
Same Base Class Libraries  More on this later...
Debugger• MonoTouch/MonoDroid debugger  leverages Mono’s Soft-Debugger• Supports the Simulator• Supports the Device - on p...
Debugger Features• Breakpoints• Catchpoints• Inspection• Watches• Immediate / Expression Evaluator• Call Stack• Stepping
Minimum CompressedMonoTouch App Size       ~1MBApp-store MinimumMonoTouch App Size      ~4MB
Minimum MonoDroid App Size (the .apk)       4.4MB    Compressed      2.2MB
Code reuse
Code reuse   Json.Net   FlickrNetXNATouch (Now MonoGame)
Rebuild your libraries• Can’t just use any DLL• Re-compile for each lib• Each framework has its own class library
Portable Library    Project      will help
Not an abstraction!
Not an abstraction!• Platform specific APIs• Platform specific look and feel
Mono for WP7?
Mono for WP7?• Look at Mono code and copy over!• IQueryable support in WP7• More later...
Porting overHanselminutes
Porting over       Hanselminuteshanselminutesiphone.codeplex.com
Porting over       Hanselminutes• Make sure your business logic is separate• Use actions for returning results
Getting XML
Persisting the XML
Isolated Storage        vs  File Storage
Storing data      void SaveLocal(string data)      {#if (MonoTouch || MonoDroid)         File.WriteAllText(_localPath, dat...
Storing data      void SaveLocal(string data)      {#if (MonoTouch || MonoDroid)         File.WriteAllText(_localPath, dat...
No File.WriteAllText?    No problem!
Implementing                  File.WriteAllTextpublic static void WriteAllText(IsolatedStorageFileStream fileStream, string...
Mono Abstractions     With MonoMobile.Extensions in the futurehttps://github.com/chrisntr/MonoMobile.Extensions
Q +Atwitter.com/chrisntrchrisntr@gmail.com
Upcoming SlideShare
Loading in …5
×

Introduction to MonoTouch and Monodroid/Mono for Android

6,950 views

Published on

Here are the slides used in my NxtGen UK Mini-tour in May 2011

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
6,950
On SlideShare
0
From Embeds
0
Number of Embeds
16
Actions
Shares
0
Downloads
94
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Introduction to MonoTouch and Monodroid/Mono for Android

  1. 1. MonoTouch andMono for Android with some Windows Phone 7 NxtGen User Group Cambridge, Shenfield & Southampton 10th -12th May 2011 Chris Hardy
  2. 2. Chris Hardy• ASPInsider• Write some books• http://twitter.com/chrisntr• Work for great fridays
  3. 3. http://greatfridays.com
  4. 4. http://emmawatson.com
  5. 5. http://dominion-funds.com
  6. 6. Covering...• How these technologies work• Demos• Similarities between MonoTouch and Mono for Android• Code Re-use with MonoTouch, Mono for Android and Windows Phone 7
  7. 7. MonoTouch
  8. 8. What is Mono? The .Net Frameworkcreated by Miguel De Icaza et al.
  9. 9. Miguel de Icaza
  10. 10. What is MonoTouch? C# and .NET on the iPhone
  11. 11. Demo - Walkthrough
  12. 12. Mono’s JIT Engine Memory MonoCIL
  13. 13. Apple Rules• Contractual Requirements • No interpreted code • No shared libraries• Kernel Limitations • iPhone OS 2.0+ disables JIT
  14. 14. Mono’s AOT Engine Native Code Mono AOT Mono RuntimeCIL ARM
  15. 15. MonoTouch Features• mtouch• MonoDevelop iPhone Add-In• CocoaTouch.NET / monotouch.dll• Full static AOT compiler• Support for all your existing code • Reflection • Generics • LINQ • Anonymous Methods • Lambda’s etc...
  16. 16. MonoTouch’s APIs
  17. 17. 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...
  18. 18. MonoTouch Events• Supports Objective-C pattern (including blocks): webView.Delegate = new MyWebViewDelegate();• C# style events as well: webView.PageLoaded += delegate { HideSpinningWheel(); }
  19. 19. 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); }
  20. 20. MonoTouch Design Integration• Integrates with Interface Builder and Xcode 3• Xcode 4 support coming
  21. 21. Demo - Integration
  22. 22. Learn to read Objective-C
  23. 23. 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...
  24. 24. 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
  25. 25. Binding against 3rd party libraries• https://github.com/chrisntr/monotouch- bindings/tree/master/BingMaps• Demo showing Bing iOS control in MonoTouch
  26. 26. Who’s using MonoTouch?• Medtronic - http://www.apple.com/ipad/ business/profiles/medtronic/• iCircuit - http://itunes.apple.com/us/app/ icircuit/id383359044?mt=8• Showcase of apps - http://monotouch.net/ Apps/?tag=/Showcase
  27. 27. 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.
  28. 28. DemoTwitter on iPhone with MonoTouch
  29. 29. What is Mono for Android?
  30. 30. What is MonoDroid? C# and .NET on Android
  31. 31. Demo
  32. 32. How does MonoDroid work?
  33. 33. What is MonoDroid? Cross-platform
  34. 34. MonoDroid Features• mandroid.exe• Visual Studio 2010 Integration• MonoDevelop MonoDroid Add-In• Mono.Android.dll• Full static AOT compiler and JIT support• Support for all your existing code • Reflection • Generics • LINQ • Anonymous Methods • Lambda’s etc...
  35. 35. What is MonoDroid?v1.0 released in March was expected late 2010...
  36. 36. What is MonoDroid?Expect rapid releases a la MonoTouch
  37. 37. What is MonoDroid?A commercial product same prices as MonoTouch
  38. 38. What is MonoDroid? Give feedback! Submit bugs! http://monodroid.net/
  39. 39. Mono for Android book on its way!Out around July
  40. 40. DemoTwitter on Android with MonoDroid
  41. 41. Similarities withMonoTouch and MonoDroid
  42. 42. Linkerand the application size...
  43. 43. What about App Size?• 20 MB (compressed) limit on 3G/Edge downloads• .Net BCL and other libraries are huge• Mono Linker to the rescue!
  44. 44. Linking Assemblies
  45. 45. Linker Options• No Link• Link SDK Only• Full Link
  46. 46. Same Base Class Libraries More on this later...
  47. 47. Debugger• MonoTouch/MonoDroid debugger leverages Mono’s Soft-Debugger• Supports the Simulator• Supports the Device - on paid versions • even over WiFi*
  48. 48. Debugger Features• Breakpoints• Catchpoints• Inspection• Watches• Immediate / Expression Evaluator• Call Stack• Stepping
  49. 49. Minimum CompressedMonoTouch App Size ~1MBApp-store MinimumMonoTouch App Size ~4MB
  50. 50. Minimum MonoDroid App Size (the .apk) 4.4MB Compressed 2.2MB
  51. 51. Code reuse
  52. 52. Code reuse Json.Net FlickrNetXNATouch (Now MonoGame)
  53. 53. Rebuild your libraries• Can’t just use any DLL• Re-compile for each lib• Each framework has its own class library
  54. 54. Portable Library Project will help
  55. 55. Not an abstraction!
  56. 56. Not an abstraction!• Platform specific APIs• Platform specific look and feel
  57. 57. Mono for WP7?
  58. 58. Mono for WP7?• Look at Mono code and copy over!• IQueryable support in WP7• More later...
  59. 59. Porting overHanselminutes
  60. 60. Porting over Hanselminuteshanselminutesiphone.codeplex.com
  61. 61. Porting over Hanselminutes• Make sure your business logic is separate• Use actions for returning results
  62. 62. Getting XML
  63. 63. Persisting the XML
  64. 64. Isolated Storage vs File Storage
  65. 65. Storing data void SaveLocal(string data) {#if (MonoTouch || MonoDroid) File.WriteAllText(_localPath, data);#elif WINDOWS_PHONE using (var appStorage =IsolatedStorageFile.GetUserStoreForApplication()) { var file = appStorage.OpenFile(_localPath, FileMode.Create); FileExtension.WriteAllText(file, data); }#endif }
  66. 66. Storing data void SaveLocal(string data) {#if (MonoTouch || MonoDroid) File.WriteAllText(_localPath, data);#elif WINDOWS_PHONE using (var appStorage =IsolatedStorageFile.GetUserStoreForApplication()) { var file = appStorage.OpenFile(_localPath, FileMode.Create); FileExtension.WriteAllText(file, data); }#endif }
  67. 67. No File.WriteAllText? No problem!
  68. 68. Implementing File.WriteAllTextpublic static void WriteAllText(IsolatedStorageFileStream fileStream, string data){ using (StreamWriter sw = new StreamWriter(fileStream)) { sw.Write(data); sw.Close(); }}public static void WriteAllText(string path, string contents){ WriteAllText(path, contents, Encoding.UTF8);}public static void WriteAllText(string path, string contents, Encoding encoding){ using (StreamWriter sw = new StreamWriter(path, false, encoding)) { sw.Write(contents); }}
  69. 69. Mono Abstractions With MonoMobile.Extensions in the futurehttps://github.com/chrisntr/MonoMobile.Extensions
  70. 70. Q +Atwitter.com/chrisntrchrisntr@gmail.com

×