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

  • View

  • Download

Embed Size (px)


Session presented at vsug Belgium

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

  • 1. Cross Platform Native Mobile App Development for iOS, Android and Windows Using the Power of C#Marcel de Vries Technology Manager @marcelv

2. Agenda Introduction to Xamarin& Mobile Creating your first iOS app Creating your first Android app Code Sharing Tips Summary 3. Building apps for the Mobile Space DeveloperUser ExperienceproductivitySecurity & privacyDistribution: Public or private Corporate?Which platforms? Application Lifecycle Management 4. Application types 5. Application types Native look & feel----++Camera Access-+++++++ ++Secure service communicationJSON/RESTJSON/RESTJSON/SOAPAccess to calendar----++Twitter integration+-+-+Distribution++AppStore presenceAppStore presenceGPS 6. 3 typesXamarinWP8/win8 Xaml + C# XamarinXamarin.iOSXamarin.AndroidXCode Objective-CWP7 Silverlight C#Adobe AIR ActionScriptAppcelerator Titanium JavaScript > NativeService2Media LuaRhodes Ruby + HTML Android SDK JavaAntenna Rapid Scripting Language Kony Javascript LuaVendor toolsSybase Unwired 4GL code genC# App LogicPhoneGap HTML5 / CSS / JSMagic BoxShared language Hybrid 7. Xamarin History Over a Decade of Enterprise Production Use 450,000 Reach 200,000 Developers Developer 100+ Partners Mark 100+ Components2000Ximian Founded2001200320092011Mono LaunchesXimian Acquired by NovellFirst iOS product (now Xamarin.iOS) launches2013Xamarin Founded2012First 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. Anything you can do in Objective-C or Java can be done in C# and Visual Studio with Xamarin. 9. Native PerformanceXamarin.iOS does full Ahead Of Time (AOT) compilation to produce an ARM binary suitable for Apples App Store.Xamarin.Android takes advantage of Just In Time (JIT) compilation on the Android device. 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. Completely Up-to-Date with Device OS releasesAlways up-to-date with the latest APIs from Apple and Google. Track record of offering sameday support: iOS 5, iOS 6, iOS6.1 and iOS 7. 12. UIKit3rd party appTap app icon main()AppDelegateUIApplicationMain()FinishedLaunchingEvent loopHandleEventQuit foreground msgOnActivated OnResignActivationBackgroundDidEnterBackground WillTerminateRestart tasks Reload state Refresh Pause tasksUI Throttle down frame ratesSave stateSave data Free resources 13. App model ViewUIView ActionsOutlets Controller NavigationControllerModel manipulationModelUIViewController 14. UITableView & Navigation 15. UITableView & Navigation Data + table cellsUITableViewDataSourceUITableViewControllerUITableViewSourceEventsUITableViewDelegate 16. Demo iOS app basics 17. AndroidMobile OS made by google Targets: Tablets and mobile phones 18. Mono for Android Architectural picture of Mono for Android .NET APIsAndroid BindingsMono (.NET Runtime)MCW ACWLinux KernelAndroid. *Java.*Dalvik (Java Runtime) 19. App model - Activity lifecycle Activity Launched Restore state hereInitialize layout hereonCreate()User navigates to the activityonStart()onRestart()onResume() Another activity App process comes into the foregroundkilledActivity runningThe 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 downUser returns to the activityUser navigates to the activity 20. Building apps on androidIntentIntentActivity IntentContent ProviderViewIntentActivityIntentViewServiceIntentBroadcast Receiver 21. Demo Android app basics 22. Services 21%Reusable 34%Per App Specific 16%Windows Phone 10% Shared 84%iOS 8% Android 10%Shared Logic 17% 23. Platform UI Design Patterns for ReuseData Serialization CachingSecurityApplication Business LogicAuthN/AuthZ Encryption Data Self DestructionUtilitiesPlatform Agnostic APIDevice servicesAnalytics LoggingGlue together the application layers 24. Design Patterns for Reuse 25. Basics ViewController ModelGPS Motion sensors Storage Etc.Services 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. 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 ActualEvents { get { // E.g. Complex linq stuff } } }// Model Usage: var foo = MainModel.Current.ActualEvents; 28. Check your water level XAML /Device SpecificValueConverterReusable Business Logic Model Property Value Transformation 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 OnSuccess, Action OnFail) { // do some logic, or service call // use actions to report result or trigger UI action } } 30. SF UIViewControlle rSF XAML ViewActivitypublic void OnSuccess(object data)public void OnFailed(Exception { e) //{Do something with data Shared Controller // Notify user // Do GetActualEvents something with error } }(Action OnSuccess, Action OnFail)Web ServicesSFModel PropertyChanged(Events) ; 31. Demo Action 32. iOSMonoTouch.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. Partial classes & methods 34. A.cs partial class A { // Half of the implementation }A.extra.cs partial class A { // The other half } 35. A.csA.iOS.cspartial 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. Demo 37. Summary Xamarin provides Native Cross platform capabilities Best of all worldsUse the power of C# BCL, LINQ, ASYNC, etcKeep abstractions as simple as possible Avoid IOC, Big frameworks Remember your on a mobile device, each cycle counts!