Cross-Platform Mobile mit C#
-
Upload
zuehlke -
Category
Technology
-
view
670 -
download
0
description
Transcript of Cross-Platform Mobile mit C#
Cross-Platform Mobile mit C#
© Zühlke 2014
Nativ Cross-compiled Hybrid Web
Mobile Entwicklungslandschaft
Beste Usability? Überschaubare Kosten?
Was ist Xamarin?
© Zühlke 2014
Was ist Xamarin?
• Cross-Compiler auf Basis von Mono
• Plattformen – iOS – Android – Mac OS X
• Entwicklungsumgebung
• Partnerschaft mit Microsoft
Cross-Platform Mobile mit C# | Kerry W. Lothrop 16. Juli 2014
© Zühlke 2014
Warum Xamarin?
• Cross-Platform – Gemeinsame Codebasis – Eine moderne Sprache (C#) für alle Plattformen
• Nativ – Performance – User Interface – API
• Xamarin Studio (Mac, Windows) oder Visual Studio (Windows)
• Wiederverwendung von Code und Know-How
• Sehr gute Dokumentation
Cross-Platform Mobile mit C# | Kerry W. Lothrop 16. Juli 2014
© Zühlke 2014
Cross-compiling
• Kompilieren aus C# (oder F#) in nativen, plattformabhängigen Code
• (Fast) vollständiger Funktionsumfang von .NET 4.5
• Durch Integration von Teilen des Frameworks steigt die Paketgröße
• Xamarin Scanner http://scan.xamarin.com
Cross-Platform Mobile mit C# | Kerry W. Lothrop 16. Juli 2014
© Zühlke 2014
Xamarin.iOS (früher MonoTouch)
• Ahead-of-time-Compiler direkt in ARM-Assembler-Code
• Keine dynamische Codegenerierung – System.Reflection.Emit fehlt – Keine Dynamic Language Runtime
16. Juli 2014 Cross-Platform Mobile mit C# | Kerry W. Lothrop
.NET C# AOT iOS-API
.app ARM binary läuft nativ
© Zühlke 2014
Xamarin.Android (früher Mono for Android)
• IL (Intermediate Language) und Mono-Runtime werden auf das Gerät deployed
• Just-in-time compiler
• Mono-Runtime läuft parallel zur Dalvik-VM
16. Juli 2014 Cross-Platform Mobile mit C# | Kerry W. Lothrop
.NET C# Android-API
.apk IL + JIT läuft nativ
kompilieren linken
Native Libraries verwenden Bindings unter iOS und Android
© Zühlke 2014
Bindings iOS
• Tool: Objective Sharpie
• Nacharbeit meist nötig
Cross-Platform Mobile mit C# | Kerry W. Lothrop 16. Juli 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
© Zühlke 2014
Bindings Android
• *.jar einfügen
• C# wird automatisch generiert (JNI)
• Transformationen müssen u.U. manuell ergänzt werden
Cross-Platform Mobile mit C# | Kerry W. Lothrop 16. Juli 2014
<metadata> <attr path="/api/package[@name='com.nostra13.universalimageloader.cache.memory.impl'] /class[@name='FIFOLimitedMemoryCache'] /method[@name='removeNext']" name="managedReturn"> Java.Lang.Object </attr> <attr path="/api/package[@name='com.nostra13.universalimageloader.core.imageaware'] /class[@name='ImageViewAware'] /method[@name='getWrappedView']" name="managedReturn"> Android.Views.View </attr> </metadata>
© Zühlke 2014
Entwicklungsumgebung
Cross-Platform Mobile mit C# | Kerry W. Lothrop 16. Juli 2014
MacBook
Windows 8 (VM) Visual Studio 2013 ReSharper Xamarin (iOS &
Android)
OS X Xcode (SDK,
Simulatoren) Xamarin.iOS Xamarin Build Host
Code Sharing
© Zühlke 2014
Code Sharing Portable Class Libraries
• Sharing auf Binary-Ebene
• Eingeschränkter Funktionsumfang
Cross-Platform Mobile mit C# | Kerry W. Lothrop 16. Juli 2014
© Zühlke 2014
Code Sharing Shared Projects
• Sharing auf Code-Ebene
• Compiler-Direktiven möglich (#if)
Cross-Platform Mobile mit C# | Kerry W. Lothrop 16. Juli 2014
Architektur
© Zühlke 2014
Architektur MVC
Cross-Platform Mobile mit C# | Kerry W. Lothrop 16. Juli 2014
View
Model Controller
© Zühlke 2014
View
Architektur MVVM
Cross-Platform Mobile mit C# | Kerry W. Lothrop 16. Juli 2014
View Android
Model
ViewModel
plattformunabhängig
data binding
View iOS
View Windows
Phone
MvvmCross
© Zühlke 2014
MvvmCross Projekt
• Open Source MVVM Framework
• Data Binding
• Dependency Injection
• Lokalisierung
• Navigation
• Portable Class Libraries
• Plugins
• NuGet
• NinjaCoder
• Stuart Lodge Cross-Platform Mobile mit C# | Kerry W. Lothrop 16. Juli 2014
© Zühlke 2014
MvvmCross Plattformen
Cross-Platform Mobile mit C# | Kerry W. Lothrop 16. Juli 2014
© Zühlke 2014
MvvmCross Erweiterbarkeit
Cross-Platform Mobile mit C# | Kerry W. Lothrop 16. Juli 2014
interface IMvxPhoneCallTask { void MakePhoneCall( string name, string number); }
View Android
Model
ViewModel
View iOS
View Windows
Phone
Windows-Phone-Dienst
Android-Dienst
iOS-Dienst
© Zühlke 2014
MvvmCross Plugins
Cross-Platform Mobile mit C# | Kerry W. Lothrop 16. Juli 2014
Demonstration
User Interface
© Zühlke 2014
User Interface Xamarin.Forms
Cross-Platform Mobile mit C# | Kerry W. Lothrop 16. Juli 2014
• Code-Sharing für den UI-Code
• XAML
• Native User-Interfaces
• Mischen von Xamarin.Forms und plattformspezifischen Views möglich
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="ButtonXaml.ButtonXamlPage"> <Button Text="Tap for click count!" Clicked="OnButtonClicked" /> </ContentPage>
Demonstration
Zusammenfassung
© Zühlke 2014
Nativ Cross-compiled Hybrid Web
Mobile Entwicklungslandschaft
Beste Usability? Überschaubare Kosten?
© Zühlke 2014
Zusammenfassung
Cross-Platform Mobile mit C# | Kerry W. Lothrop 16. Juli 2014
• Cross-Platform für alle wichtigen Endgeräte ohne JavaScript
• Native Performance und Möglichkeiten
• Mit bekannten Tools mehr Plattformen erreichen
• Die jeweilige plattformspezifische UI-Technologie muss trotzdem erlernt werden.
• Lizenzkosten lohnen sich oft schon bei nur einer Plattform
• Code, der während dieser Präsentation entstanden ist: https://github.com/lothrop/MvvmCrossDemo
Kontaktieren Sie mich! Gerne beantworte ich Ihre Fragen…
Mein Profil auf LinkedIn
Hier twittere ich…
Mein Profil auf Xing