Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Cross Platform Native Mobile App
Development for iOS, Android and
Windows Using the Power of C#

Marcel de Vries
Technolog...
Agenda
Introduction to Xamarin& Mobile
Creating your first iOS app
Creating your first Android app
Code Sharing Tips
Summa...
Building apps for the Mobile Space
Developer

User
Experience

productivity

Security &
privacy

Distribution:
Public or p...
Application types
Application types
Native look & feel

--

--

++

Camera Access

-++

+++

++
++

Secure service communication

JSON/REST
...
3 types

Xamarin

WP8/win8
Xaml + C#
Xamarin

Xamarin.iOS

Xamarin.Android

XCode
Objective-C

WP7
Silverlight
C#

Adobe A...
Xamarin History
Over a Decade of Enterprise Production Use
450,000
Reach 200,000
Developers
Developer
100+ Partners
Mark
1...
Anything you can do in Objective-C or Java can be
done in C# and Visual Studio with Xamarin.
Native Performance

Xamarin.iOS does full Ahead Of
Time (AOT) compilation to produce
an ARM binary suitable for Apple’s
Ap...
Accelerate Development with Code
Sharing
Code sharing statistics from production Xamarin app: real-time
circuit simulator ...
Completely Up-to-Date with Device OS releases

Always up-to-date with the
latest APIs from Apple and
Google.
Track record ...
UIKit

3rd party app

Tap app icon
main()

AppDelegate

UIApplicationMain()

FinishedLaunching

Event loop

HandleEvent

Q...
App model
View

UIView
Actions

Outlets
Controller
NavigationController

Model manipulation

Model

UIViewController
UITableView & Navigation
UITableView & Navigation
Data + table cells

UITableViewDataSource

UITableViewController

UITableViewSource

Events

UITa...
Demo
iOS app basics
Android

Mobile OS made by google
Targets: Tablets and mobile phones
Mono for Android
Architectural picture of Mono for Android
.NET APIs

Android
Bindings

Mono (.NET Runtime)

MCW
ACW

Linu...
App model - Activity lifecycle
Activity
Launched
Restore
state here

Initialize
layout here

onCreate()

User navigates to...
Building apps on android

Intent

Intent

Activity
Intent

Content
Provider

View

Intent

Activity

Intent

View

Service...
Demo
Android app basics
Services
21%

Reusable
34%

Per App
Specific
16%

Windows
Phone
10%
Shared
84%

iOS
8%
Android
10%

Shared Logic
17%
Platform UI
Design Patterns for Reuse

Data
Serialization
Caching

Security

Application Business Logic

AuthN/AuthZ
Encry...
Design Patterns for Reuse
Basics
View

Controller
Model

GPS
Motion sensors
Storage
Etc.

Services
Model Implementation
We implement the Model as a Singleton
Model Implements INotifyPropertyChanged
Easy to enlist subscrib...
Model Implementation
public class MainModel : INotifyPropertyChanged
{
private static MainModel _model;
private static obj...
Check your water level
XAML /

Device Specific

ValueConverter

Reusable Business Logic
Model Property
Value
Transformatio...
public class ISKEController
{
private static ISKEController _instance;
private ISKEDomainServicesoap _proxy;
public static...
S

F
UIViewControlle
r

S

F
XAML View

Activity

public void OnSuccess(object
data)public void OnFailed(Exception
{
e)
//...
Demo
Action<T>
iOS

MonoTouch.CoreLocation
MonoTouch.CoreMotion
MonoTouch.AVFoundation
MonoTouch.AddressBook
MonoTouch.EventKit
…

Androi...
Partial classes &
methods
A.cs
partial class A
{
// Half of the implementation
}

A.extra.cs
partial class A
{
// The other half
}
A.cs

A.iOS.cs

partial classAlways private and returns
A
{
void
// Declare the method here
partial void DoSomethingEx();
...
Demo
Summary
Xamarin provides Native Cross platform
capabilities
– Best of all worlds

Use the power of C#
– BCL, LINQ, ASYNC, ...
Cross platform native mobile app development for iOS, Android and Windows using the power of C#
Cross platform native mobile app development for iOS, Android and Windows using the power of C#
Cross platform native mobile app development for iOS, Android and Windows using the power of C#
Cross platform native mobile app development for iOS, Android and Windows using the power of C#
Cross platform native mobile app development for iOS, Android and Windows using the power of C#
Cross platform native mobile app development for iOS, Android and Windows using the power of C#
Upcoming SlideShare
Loading in …5
×

Cross platform native mobile app development for iOS, Android and Windows using the power of C#

4,146 views

Published on

Session presented at vsug Belgium

Published in: Technology
  • Be the first to comment

Cross platform native mobile app development for iOS, Android and Windows using the power of C#

  1. 1. Cross Platform Native Mobile App Development for iOS, Android and Windows Using the Power of C# Marcel de Vries Technology Manager @marcelv
  2. 2. Agenda Introduction to Xamarin& Mobile Creating your first iOS app Creating your first Android app Code Sharing Tips Summary
  3. 3. Building apps for the Mobile Space Developer User Experience productivity Security & privacy Distribution: Public or private Corporate? Which platforms? Application Lifecycle Management
  4. 4. Application types
  5. 5. Application types Native look & feel -- -- ++ Camera Access -++ +++ ++ ++ Secure service communication JSON/REST JSON/REST JSON/SOAP Access to calendar -- -- ++ Twitter integration +- +- + Distribution ++ AppStore presence AppStore presence GPS
  6. 6. 3 types Xamarin WP8/win8 Xaml + C# Xamarin Xamarin.iOS Xamarin.Android XCode Objective-C WP7 Silverlight C# Adobe AIR ActionScript Appcelerator Titanium JavaScript > Native Service2Media Lua Rhodes Ruby + HTML Android SDK Java Antenna Rapid Scripting Language Kony Javascript Lua Vendor tools Sybase Unwired “4GL” code gen C# App Logic PhoneGap HTML5 / CSS / JS “Magic Box” Shared language Hybrid
  7. 7. Xamarin History Over a Decade of Enterprise Production Use 450,000 Reach 200,000 Developers Developer 100+ Partners Mark 100+ Components 2000 Ximian Founded 2001 2003 2009 2011 Mono Launches Ximian Acquired by Novell First iOS product (now Xamarin.iOS) launches 2013 Xamarin Founded 2012 First Xamarin 2.0 release of Xamarin.Mac Component First Store Release of Launch Xamarin Test Xamarin.Android Partner Cloud Program Evolve 2013 Microsoft Partnership
  8. 8. Anything you can do in Objective-C or Java can be done in C# and Visual Studio with Xamarin.
  9. 9. Native Performance Xamarin.iOS does full Ahead Of Time (AOT) compilation to produce an ARM binary suitable for Apple’s App Store. Xamarin.Android takes advantage of Just In Time (JIT) compilation on the Android device.
  10. 10. Accelerate Development with Code Sharing Code sharing statistics from production Xamarin app: real-time circuit simulator and editor used to design analog and digital circuits
  11. 11. Completely Up-to-Date with Device OS releases Always up-to-date with the latest APIs from Apple and Google. Track record of offering sameday support: iOS 5, iOS 6, iOS ✔ 6.1 and iOS 7.
  12. 12. UIKit 3rd party app Tap app icon main() AppDelegate UIApplicationMain() FinishedLaunching Event loop HandleEvent Quit foreground msg OnActivated OnResignActivation Background DidEnterBackground WillTerminate Restart tasks Reload state Refresh Pause tasksUI Throttle down frame rates Save state Save data Free resources
  13. 13. App model View UIView Actions Outlets Controller NavigationController Model manipulation Model UIViewController
  14. 14. UITableView & Navigation
  15. 15. UITableView & Navigation Data + table cells UITableViewDataSource UITableViewController UITableViewSource Events UITableViewDelegate
  16. 16. Demo iOS app basics
  17. 17. Android Mobile OS made by google Targets: Tablets and mobile phones
  18. 18. Mono for Android Architectural picture of Mono for Android .NET APIs Android Bindings Mono (.NET Runtime) MCW ACW Linux Kernel Android. * Java.* Dalvik (Java Runtime)
  19. 19. App model - Activity lifecycle Activity Launched Restore state here Initialize layout here onCreate() User navigates to the activity onStart() onRestart() onResume() Another activity App process comes into the foreground killed Activity running The activity is no longer visible Apps with higher state The activitySave is finishing or being onPause() priority need destroyed by the system memory here onStop() onDestroy() Activity shut down User returns to the activity User navigates to the activity
  20. 20. Building apps on android Intent Intent Activity Intent Content Provider View Intent Activity Intent View Service Intent Broadcast Receiver
  21. 21. Demo Android app basics
  22. 22. Services 21% Reusable 34% Per App Specific 16% Windows Phone 10% Shared 84% iOS 8% Android 10% Shared Logic 17%
  23. 23. Platform UI Design Patterns for Reuse Data Serialization Caching Security Application Business Logic AuthN/AuthZ Encryption Data Self Destruction Utilities Platform Agnostic API Device services Analytics Logging Glue together the application layers
  24. 24. Design Patterns for Reuse
  25. 25. Basics View Controller Model GPS Motion sensors Storage Etc. Services
  26. 26. Model Implementation We implement the Model as a Singleton Model Implements INotifyPropertyChanged Easy to enlist subscribers Facilitate automatic databinding in XAML Model contains rich features such as filtering and advanced selections Easy to share logic
  27. 27. Model Implementation public class MainModel : INotifyPropertyChanged { private static MainModel _model; private static object _lockHandle = new object(); // Facilitates Windows Phone app resume public void RestoreState(MainModel state) { _model = state; } public static MainModel Current { get { if (_model == null) { _model = new MainModel(); } return _model; } } public IEnumerable<Event> ActualEvents { get { // E.g. Complex linq stuff } } } // Model Usage: var foo = MainModel.Current.ActualEvents;
  28. 28. Check your water level XAML / Device Specific ValueConverter Reusable Business Logic Model Property Value Transformation
  29. 29. public class ISKEController { private static ISKEController _instance; private ISKEDomainServicesoap _proxy; public static ISKEController Current { get { if (_instance == null) { _instance = new ISKEController(); } return _instance; } } private void GetActualEvents (Action<object> OnSuccess, Action<Exception> OnFail) { // do some logic, or service call // use actions to report result or trigger UI action } }
  30. 30. S F UIViewControlle r S F XAML View Activity public void OnSuccess(object data)public void OnFailed(Exception { e) //{Do something with data Shared Controller // Notify user // Do GetActualEvents something with error } } (Action<object> OnSuccess, Action<Exception> OnFail) Web Services S F Model PropertyChanged(“Events”) ;
  31. 31. Demo Action<T>
  32. 32. iOS MonoTouch.CoreLocation MonoTouch.CoreMotion MonoTouch.AVFoundation MonoTouch.AddressBook MonoTouch.EventKit … Android: Android.Hardware.Sensor Android.Location Android.Bluetooth Android.Nfc … Windows Phone: Microsoft.Devices.Sensors.Gyroscope Microsoft.Devices.Sensors.Accelerometer Microsoft.Devices.Sensors.Compass Microsoft.Devices.Sensors.Motion …
  33. 33. Partial classes & methods
  34. 34. A.cs partial class A { // Half of the implementation } A.extra.cs partial class A { // The other half }
  35. 35. A.cs A.iOS.cs partial classAlways private and returns A { void // Declare the method here partial void DoSomethingEx(); partial class A { // Provide the implementation here partial void DoSomethingEx() { public void DoSomething() // Do something iOS specific { } // Some shared logic be used from shared } Can Leaves room for specific DoSomethingEx(); logic implementation } }
  36. 36. Demo
  37. 37. Summary Xamarin provides Native Cross platform capabilities – Best of all worlds Use the power of C# – BCL, LINQ, ASYNC, etc Keep abstractions as simple as possible – Avoid IOC, Big frameworks – Remember your on a mobile device, each cycle counts!

×