cross-platform mobile with c#

31
Cross-platform mobile with C#

Upload: zuehlke

Post on 30-Nov-2014

783 views

Category:

Technology


3 download

DESCRIPTION

Write once, run everywhere? There are several solutions to achieve this goal for mobile devices. This presentation introduces Xamarin's cross-compile solution which allows maintaining a common code basis for the most important platforms while still enabling native user interfaces. In the course of this presentation, I will create an app from scratch using Visual Studio and the MvvmCross framework which allows code sharing up to the ViewModel level and implements native user interfaces for Android and iOS at the same time. Presentation held at http://www.developer-week.de/ 2014

TRANSCRIPT

  • 1. Cross-platform mobile with C#
  • 2. Zhlke 2014 Native Cross- compiled Hybrid Web Mobile development space Best usability? Manageable cost?
  • 3. What is Xamarin?
  • 4. Zhlke 2014 What is Xamarin? Cross-compiler based on Mono Platforms iOS Android Mac OS X Development environment Partnership with Microsoft Cross-platform mobile with C# | Kerry W. Lothrop July 16 2014
  • 5. Zhlke 2014 Why Xamarin? Cross-platform Shared code base One modern language (C#) for all platforms Native Performance User interface API Xamarin Studio (Mac, Windows) or Visual Studio (Windows) Re-using code and know-how Very good documentation Cross-platform mobile with C# | Kerry W. Lothrop July 16 2014
  • 6. Zhlke 2014 Cross-compiling Compiling from C# (or F#) to native, platform- independent code (Almost) complete functionality of .NET 4.5 Package size increases by integrating parts of the framework Xamarin Scanner http://scan.xamarin.com Cross-platform mobile with C# | Kerry W. Lothrop July 16 2014
  • 7. Zhlke 2014 Xamarin.iOS (formerly MonoTouch) Ahead-of-time compile directly to ARM assembly code No dynamic code generation System.Reflection.Emit is missing No Dynamic Language Runtime July 16 2014Cross-platform mobile with C# | Kerry W. Lothrop .NET C# AOT iOS-API .app ARM binary runs natively
  • 8. Zhlke 2014 Xamarin.Android (formerly Mono for Android) IL (Intermediate Language) and Mono runtime are deployed onto the device Just-in-time compiler Mono runtime runs parallel to Dalvik VM July 16 2014Cross-platform mobile with C# | Kerry W. Lothrop .NET C# Android-API .apk IL + JIT runs natively compile link
  • 9. Using native libraries Bindings for iOS and Android
  • 10. Zhlke 2014 Bindings iOS Tool: Objective Sharpie Rework often necessary Cross-platform mobile with C# | Kerry W. Lothrop July 16 2014 .h [BaseType(typeof(NSObject))] interface MyClass { // Method [Export("draw:atColumn:andRow:")] void Draw(string text, int column, int row); // Property [Export("menuVisible")] bool MenuVisible { [Bind("isMenuVisible")] get; set; } } .cs
  • 11. Zhlke 2014 Bindings Android Insert *.jar C# is automatically generated (JNI) Transformationen may need to be amended Cross-platform mobile with C# | Kerry W. Lothrop July 16 2014 Java.Lang.Object Android.Views.View
  • 12. Zhlke 2014 Development environment Cross-platform mobile with C# | Kerry W. Lothrop July 16 2014 MacBook Windows 8 (VM) Visual Studio 2013 ReSharper Xamarin (iOS & Android) OS X Xcode (SDK, simulators) Xamarin.iOS Xamarin Build Host
  • 13. Code Sharing
  • 14. Zhlke 2014 Code Sharing Portable Class Libraries Sharing at binary level Limited functionality Cross-platform mobile with C# | Kerry W. Lothrop July 16 2014
  • 15. Zhlke 2014 Code Sharing Shared Projects Sharing at code level Compiler directives possible (#if) Cross-platform mobile with C# | Kerry W. Lothrop July 16 2014
  • 16. Architecture
  • 17. Zhlke 2014 Architecture MVC Cross-platform mobile with C# | Kerry W. Lothrop July 16 2014 View Model Controller
  • 18. Zhlke 2014 View Architecture MVVM Cross-platform mobile with C# | Kerry W. Lothrop July 16 2014 View Android Model ViewModel platform- independent data binding View iOS View Windows Phone
  • 19. MvvmCross
  • 20. Zhlke 2014 MvvmCross Project Open source MVVM framework Data binding Dependency injection Localization Navigation Portable Class Libraries Plugins NuGet NinjaCoder Stuart Lodge Cross-platform mobile with C# | Kerry W. Lothrop July 16 2014
  • 21. Zhlke 2014 MvvmCross Platforms Cross-platform mobile with C# | Kerry W. Lothrop July 16 2014
  • 22. Zhlke 2014 MvvmCross Extendability Cross-platform mobile with C# | Kerry W. Lothrop July 16 2014 interface IMvxPhoneCallTask { void MakePhoneCall( string name, string number); } View Android Model ViewModel View iOS View Windows Phone Windows Phone service Android service iOS service
  • 23. Zhlke 2014 MvvmCross Plugins Cross-platform mobile with C# | Kerry W. Lothrop July 16 2014
  • 24. Demonstration
  • 25. User Interface
  • 26. Zhlke 2014 User Interface Xamarin.Forms Cross-platform mobile with C# | Kerry W. Lothrop July 16 2014 Code sharing for UI Code XAML Native user interfaces Mixing of Xamarin.Forms and plattform-specific views is possible
  • 27. Demonstration
  • 28. Summary
  • 29. Zhlke 2014 Native Cross- compiled Hybrid Web Mobile development space Best usability? Manageable cost?
  • 30. Zhlke 2014 Summary Cross-platform mobile with C# | Kerry W. Lothrop July 16 2014 Cross-platform for all relevant devices without JavaScript Native performance und possibilities Reach more platforms with known existing tools Each platform-specific UI technologie still needs to be learned. Licensing cost can pay off even when targeting only one platform. Code created during this presentation: https://github.com/lothrop/MvvmCrossDemo
  • 31. Please share the slides if you liked them Lets connect on LinkedIn Follow me on Twitter My profile on Xing