You are previewing Xamarin: Cross-Platform Mobile Application Development.
O'Reilly logo
Xamarin: Cross-Platform Mobile Application Development

Book Description

Master the skills required to develop cross-platform applications from drawing board to app store(s) using Xamarin

About This Book

  • Learn to deliver high-performance native apps that leverage platform specific acceleration, complied for native performance

  • Learn development techniques that will allow you to use and create custom layouts for cross-platform UI

  • Gain the knowledge needed to become more efficient in testing, deploying, and monitoring your applications

  • Implement application life cycle management concepts to manage cross-platform projects

  • Who This Book Is For

    Mobile application developers wanting to develop skills required to steer cross-platform applications using Xamarin.

    What You Will Learn

  • Share C# code across platforms and call native Objective-C or Java libraries from C#

  • Submit your app to the Apple App Store and Google Play

  • Use the out-of-the-box services to support third-party libraries

  • Find out how to get feedback while your application is used by your users

  • Create shared data access using a local SQLite database and a REST service

  • Test and monitor your applications

  • Gain memory management skills to avoid memory leaks and premature code cycles while decreasing the memory print of your applications

  • Integrate network resources with cross-platform applications

  • Design and implement eye-catching and reusable UI components without compromising on nativity in mobile applications

  • In Detail

    Developing a mobile application for just one platform is becoming a thing of the past. Companies expect their apps to be supported on iOS, Android and Windows Phone, while leveraging the best native features on all three platforms. Xamarin's tools help ease this problem by giving developers a single toolset to target all three platforms. The main goal of this course is to equip you with knowledge to successfully analyze, develop, and manage Xamarin cross-platform projects using the most efficient, robust, and scalable implementation patterns.

    Module 1 is a step-by-step guide to building real-world applications for iOS and Android. The module walks you through building a chat application, complete with a backend web service and native features such as GPS location, camera, and push notifications. Additionally, you'll learn how to use external libraries with Xamarin and Xamarin.Forms. Module 2 provide you recipes on how to create an architecture that will be maintainable, extendable, use Xamarin.Forms plugins to boost productivity. We start with a simple creation of a Xamarin.Forms solution, customize the style and behavior of views for each platform. Further on, we demonstrate the power of architecting a cross-platform solution. Next, you will utilize and access hardware features that vary from platform to platform with cross-platform techniques. You will master the steps of getting the app ready and publishing it in the app store. The last module starts with general topics such as memory management, asynchronous programming, local storage, networking, and platform-specific features. You will learn about key tools to leverage the pattern and advanced implementation strategies. Finally, we show you the toolset for application lifecycle management to help you prepare the development pipeline to manage and see cross-platform projects through to public or private release. After the completion of this course, you will learn a path that will get you up and running with developing cross-platform mobile applications and help you become the go-to person when it comes to Xamarin.

    Style and approach

    This course will serve as comprehensive guide for developing cross-platform applications with Xamarin with a unique approach that will engage you like never before as you create real-world cross-platform apps on your own.

    Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

    Table of Contents

    1. Xamarin: Cross-Platform Mobile Application Development
      1. Table of Contents
      2. Xamarin: Cross-Platform Mobile Application Development
      3. Xamarin: Cross-Platform Mobile Application Development
      4. Credits
      5. Preface
        1. What this learning path covers
        2. What you need for this learning path
              1. Module 1:
              2. Module 2:
              3. Module 3:
        3. Who this learning path is for
        4. Reader feedback
        5. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      6. 1. Module 1
        1. 1. Setting Up Xamarin
          1. The Xamarin tools
          2. Installing Xcode
          3. Installing Xamarin
          4. Choosing a Xamarin license
          5. Setting up the Android emulator
          6. Enrolling in the iOS Developer Program
          7. Registering as a Google Play developer
          8. Summary
        2. 2. Hello, Platforms!
          1. Building your first iOS application
          2. Understanding Apple's MVC pattern
          3. Using the iOS designer
          4. Building your first Android application
          5. Android activities
          6. Xamarin's Android designer
          7. Summary
        3. 3. Code Sharing between iOS and Android
          1. Learning the MVVM design pattern
            1. Implementing MVVM in an example
          2. Comparing project organization strategies
            1. Setting up a cross-platform solution
          3. Working with Portable Class Libraries
            1. Using PCLs in Xamarin
          4. Using preprocessor statements
          5. Simplifying dependency injection
          6. Implementing Inversion of Control
          7. Summary
        4. 4. XamChat – a Cross-platform App
          1. Starting our sample application concept
          2. Developing our Model layer
          3. Writing a mock web service
          4. Writing the ViewModel layer
            1. Implementing our LoginViewModel class
            2. Implementing our RegisterViewModel class
            3. Implementing our FriendViewModel class
            4. Implementing our MessageViewModel class
          5. Writing unit tests
            1. Setting up a new project for unit tests
            2. Writing assertions
          6. Summary
        5. 5. XamChat for iOS
          1. Understanding the basics of an iOS app
          2. Using UINavigationController
            1. Methods in Navigation Controllers
            2. Setting up a Navigation Controller
          3. Implementing the login screen
            1. Creating a LoginController class
            2. Modifying the controller's layout
            3. Registering and subscribing view models and services
          4. Using segues and UITableView
          5. Adding a friends list screen
          6. Adding a list of messages
          7. Composing messages
          8. Summary
        6. 6. XamChat for Android
          1. Introducing Android Manifest
            1. Setting up the Manifest
              1. Common manifest permissions
            2. Creating and implementing the application class
          2. Adding a login screen
            1. Layouts and ViewGroups in Andorid
            2. Implementing the login functionality
          3. Using ListView and BaseAdapter
            1. Implementing the conversations screen
            2. Setting up the adapter
          4. Implementing the friends list
          5. Composing messages
          6. Summary
        7. 7. Deploying and Testing on Devices
          1. iOS provisioning
            1. Prerequisites for deploying to iOS
            2. Creating a provisioning profile
          2. Android device settings
          3. Understanding the linker
          4. Understanding AOT compilation
          5. Avoiding common memory pitfalls
            1. Garbage collector
            2. Memory leaks
            3. Accessing objects disposed by GC
          6. Summary
        8. 8. Web Services with Push Notifications
          1. Learning Windows Azure
          2. Setting up your Azure account
          3. Exploring Azure Mobile Services
          4. Creating tables and scripts
          5. Adding a backend to XamChat
            1. Adding the Azure Mobile Services NuGet package
          6. Using the Apple Push Notification service
            1. Setting up proper provisioning
            2. Setting up your provisioning profile
            3. Setting up a certificate signing request
            4. Making client-side changes for push notifications
          7. Implementing Google Cloud Messaging
          8. Summary
        9. 9. Third-party Libraries
          1. The Xamarin Component Store
            1. The most common components
          2. Porting existing C# libraries
          3. Objective-C bindings
            1. Working with Objective Sharpie
          4. Java bindings
          5. Summary
        10. 10. Contacts, Camera, and Location
          1. Introducing Xamarin.Mobile
          2. Accessing contacts
            1. Retrieving contacts on Android
          3. Looking up GPS location
            1. Implementing GPS location on Android
          4. Accessing the photo library and camera
            1. Accessing photos on Android
          5. Summary
        11. 11. Xamarin.Forms
          1. Creating Hello World in Xamarin.Forms
          2. Understanding the architecture behind Xamarin.Forms
          3. Using XAML in Xamarin.Forms
          4. Using data binding and MVVM
          5. Summary
        12. 12. App Store Submission
          1. Following the iOS App Store Review Guidelines
            1. General rules
            2. Incorrect and incomplete information
            3. Content present in the application
            4. Apple's 70/30 revenue share
            5. General Tips
          2. Submitting an app to the iOS App Store
            1. Creating a distribution provisioning profile
            2. Adding your app to iTunes Connect
            3. Making an iOS binary for the App Store
          3. Signing your Android applications
          4. Submitting the app to Google Play
            1. Google Play Developer Program Policies
          5. Tips to make a successful mobile app
          6. Summary
      7. 2. Module 2
        1. 1. One Ring to Rule Them All
          1. Introduction
          2. Creating a cross-platform solution
            1. Getting ready
            2. How to do it...
            3. How it works…
            4. See also
          3. Creating a cross-platform login screen
            1. How to do it...
            2. How it works…
            3. There's more…
          4. Using common platform features
            1. How to do it...
            2. How it works…
            3. See also
          5. Authenticating with Facebook and Google providers
            1. How to do it...
              1. For the Android project
              2. For the iOS project
            2. How it works…
            3. See also
        2. 2. Declare Once, Visualize Everywhere
          1. Introduction
          2. Creating a tabbed-page cross-platform application
            1. How to do it…
            2. How it works…
            3. See also
          3. Adding UI behaviors and triggers
            1. How to do it…
            2. How it works…
            3. See also
          4. Configuring XAML with platform-specific values
            1. How to do it…
            2. How it works…
            3. See also
          5. Using custom renderers to change the look and feel of views
            1. How to do it…
            2. How it works…
            3. See also
        3. 3. Native Platform-Specific Views and Behavior
          1. Introduction
          2. Showing native pages with renderers
            1. How to do it…
            2. How it works…
            3. See also
          3. Attaching platform-specific gestures
            1. How to do it…
            2. How it works…
            3. See also
          4. Taking an in-app photo with the native camera page
            1. How to do it…
            2. How it works…
            3. See also
        4. 4. Different Cars, Same Engine
          1. Introduction
          2. Sharing code between different platforms
            1. How to do it…
            2. How it works…
            3. See also
          3. Using the dependency locator
            1. How to do it…
            2. How it works…
            3. See also
          4. Adding a third-party Dependency Injection Container
            1. How to do it…
            2. How it works…
            3. See also
          5. Architecture design with Model-View-ViewModel (MVVM) pattern
            1. How to do it…
            2. How it works…
            3. There's more…
            4. See also
          6. Using the event messenger
            1. How to do it…
            2. How it works…
            3. See also
          7. Adding localization
            1. How to do it…
            2. How it works…
            3. There's more…
        5. 5. Dude, Where's my Data?
          1. Introduction
          2. Creating a shared SQLite data access
            1. How to do it…
            2. How it works…
            3. See also
          3. Performing CRUD operations in SQLite
            1. How to do it…
            2. How it works…
            3. See also
          4. Consuming REST web services
            1. How to do it…
            2. How it works…
          5. Leveraging native REST libraries and making efficient network calls
            1. How to do it…
            2. How it works…
            3. There's more…
        6. 6. One for All and All for One
          1. Introduction
          2. Creating cross-platform plugins
            1. How to do it...
            2. How it works…
            3. There's more…
            4. See also
          3. Taking or choosing photos
            1. How to do it…
            2. How it works…
            3. There's more…
            4. See also
          4. Getting the GPS location
            1. How to do it…
            2. How it works…
            3. See also
          5. Show and schedule local notifications
            1. How to do it…
            2. How it works…
            3. There's more…
        7. 7. Bind to the Data
          1. Introduction
          2. Binding data in code
            1. How to do it…
            2. How it works…
          3. Binding data in XAML
            1. How to do it…
            2. How it works…
          4. Configuring two-way data binding
            1. How to do it…
            2. How it works…
            3. See also
          5. Using value converters
            1. How to do it…
            2. How it works…
            3. See also
        8. 8. A List to View
          1. Introduction
          2. Displaying a collection and selecting a row
            1. How to do it…
            2. How it works…
            3. See also
          3. Adding, removing, and refreshing items
            1. How to do it…
            2. How it works…
            3. There's more…
            4. See also
          4. Customizing the row template
            1. How to do it…
            2. How it works…
            3. There's more…
            4. See also
          5. Adding grouping and a jump index list
            1. How to do it…
            2. How it works…
            3. There's more…
            4. See also
        9. 9. Gestures and Animations
          1. Introduction
          2. Adding gesture recognizers in XAML
            1. How to do it…
            2. How it works…
            3. There's more…
            4. See also
          3. Handling gestures with native platform renderers
            1. How to do it…
            2. How it works…
          4. Adding cross-platform animations
            1. How to do it…
            2. How it works…
            3. There's more…
        10. 10. Test Your Applications, You Must
          1. Introduction
          2. Creating unit tests
            1. How to do it…
            2. How it works…
          3. Creating acceptance tests with Xamarin.UITest
            1. How to do it…
            2. How it works…
            3. There's more…
            4. See also
          4. Using the Xamarin.UITest REPL runtime shell to test the UI
            1. How to do it…
            2. How it works…
            3. See also
          5. Uploading and running tests in Xamarin Test Cloud
            1. How to do it…
            2. How it works…
            3. There's more…
            4. See also
        11. 11. Three, Two, One – Launch and Monitor
          1. Introduction
          2. Using Xamarin Insights
            1. How to do it…
            2. How it works…
            3. There's more…
          3. Publishing iOS applications
            1. How to do it…
            2. How it works…
          4. Publishing Android applications
            1. How to do it…
            2. How it works…
            3. There's more…
            4. See also
          5. Publishing Windows Phone applications
            1. How to do it…
            2. How it works…
            3. There's more…
      8. 3. Module 3
        1. 1. Developing with Xamarin
          1. Cross-platform projects with Xamarin
            1. Xamarin as a platform
            2. Xamarin as a product
          2. Target platforms
            1. Xamarin on Android
            2. Xamarin on iOS
            3. Windows Runtime apps
          3. Setting up the development environment
            1. Choosing the right development OS
              1. Xamarin Studio setup and configuration
              2. Visual Studio setup and configuration
          4. Emulator options
            1. Emulators for Android
            2. iOS emulation
          5. A typical Xamarin solution structure
            1. Portable class libraries
            2. Shared projects
            3. Xamarin.Forms
            4. NuGet packages
            5. Components
          6. Quality in cross-development
            1. Reusability
            2. Abstraction
            3. Loose-coupling
            4. Nativity
          7. Summary
        2. 2. Memory Management
          1. Application Component lifecycle
            1. Activity lifecycle (Android)
              1. Active/Running
              2. Paused
              3. Backgrounded
              4. Stopped
              5. Restarted
            2. Application lifecycle (iOS)
          2. Garbage collection
            1. GC on Xamarin projects
              1. SGen garbage collector
              2. Boehm garbage collector (iOS only)
          3. Platform-specific concepts
            1. Object reference types
            2. Automatic Reference Counting (ARC)
          4. Troubleshooting and diagnosis
            1. Xamarin Profiler
              1. Allocations instrument
              2. Time Profiler
            2. Device Monitor (Android only)
            3. Instruments (iOS only)
            4. Monotouch Profiler (iOS only)
          5. Patterns and best practices
            1. Disposable objects
            2. The lapsed listener problem
            3. Weak references
            4. Cross-domain objects
            5. Cyclic references (cycles)
          6. Summary
        3. 3. Asynchronous Programming
          1. Multithreading on Xamarin
            1. Single thread model
            2. Task-based Asynchronous Pattern
            3. Concurrency model on iOS
          2. Asynchronous methods
            1. Continuation
            2. Cancellation
            3. Progress
            4. Task batches
          3. Parallel execution
          4. Patterns and best practices
            1. Async pattern conversions
            2. Multi-threading with tasks
            3. Exception handling
            4. Initialization pattern
            5. Semaphores
          5. Background tasks
            1. Background tasks on iOS
            2. Services (Android only)
          6. Summary
        4. 4. Local Data Management
          1. Data in mobile applications
            1. State
            2. App data
            3. Local files
            4. External data
          2. Application data
            1. Installation directory
              1. Android
              2. iOS
            2. Local storage
              1. Android
              2. iOS
            3. Temporary storage
          3. Local filesystem
          4. SQLite
          5. Patterns and best practices
            1. Application preferences
            2. File picker
          6. Backup/Roaming
            1. Android and Backup API
            2. iOS and ubiquitous storage
          7. Summary
        5. 5. Networking
          1. Connected apps
          2. Web services
            1. Transport
            2. Messaging
            3. SOAP/XML services
            4. RESTful services
            5. OData and OAuth
              1. OData
              2. OAuth
          3. SignalR
          4. Patterns and best practices
            1. Async conversions
            2. Data model abstraction
            3. Service cache
          5. Platform-specific concepts
            1. Permissions
            2. NSUrlConnection/NSUrlSession (iOS Only)
            3. Background downloads
            4. Push notifications
          6. Cloud integration
            1. Azure Mobile Services
            2. Azure offline data
            3. Azure authentication
          7. Summary
        6. 6. Platform Extras
          1. Content sharing
            1. File pickers and contracts (Windows Store apps)
            2. Document Provider extensions (iOS)
            3. ContentProvider and ContentResolver (Android)
          2. Peripherals
            1. Bluetooth
            2. Wi-Fi Direct
            3. Near Field Communication
          3. Location data
            1. Android location and Google Play services
            2. Location services on iOS
            3. Location data on Windows Runtime
            4. Geofencing
          4. Native libraries
            1. Managed callable wrappers (Android)
            2. Linking versus binding (iOS)
          5. Summary
        7. 7. View Elements
          1. Design philosophy
            1. User expectations
            2. Platform imperatives
            3. Hardware dependency
              1. Design metrics on Android
                1. Design metrics on iOS
                2. Design metrics on Windows Runtime
          2. Design elements
            1. The basic layout
            2. Navigation
              1. Horizontal navigation
              2. Vertical navigation
              3. Jump navigation
            3. Content elements
              1. Collection views
                1. UITableView (iOS)
                2. UICollectionView (iOS)
                3. ListView (Android)
                4. GridView (Android)
                5. CardView (Android)
                6. ListView and ListBox (Windows Phone)
                7. GridView (Windows Phone)
                8. Virtualizing panels (Windows Phone)
              2. Modal views
                1. Popover and alerts (iOS)
                2. Flyout, popups, and menus (Windows Phone)
                3. Dialogs (Android)
              3. Text views
              4. Web views
            4. Feedback
              1. Indeterminate progress
              2. Determinate progress
          3. User interaction
            1. Interactive controls
              1. Text input
              2. Dropdown selection
              3. Option selection
            2. Gestures
          4. Summary
        8. 8. Xamarin.Forms
          1. Under the hood
            1. Anatomy of Xamarin.Forms
            2. Project structure
          2. Components
            1. Pages
              1. Tabbed page
              2. The MasterDetail page
              3. NavigationPage
              4. CarouselPage
              5. ContentPage
            2. Layouts
            3. Views
          3. Extending forms
            1. Styles
            2. Triggers and behaviors
            3. Custom renderers
          4. Patterns and best practices
            1. Messaging infrastructure
            2. Dependency injection
            3. Shared project versus portable project
            4. Platform-specific fine-tuning
          5. Summary
        9. 9. Reusable UI Patterns
          1. Visual assets
            1. Text resources
              1. Xamarin.Android
              2. Xamarin.iOS
              3. Windows Phone
            2. Image resources
            3. Adaptive visual assets
            4. Reusable assets
          2. Localization
            1. Locale and culture
            2. Windows Phone
            3. Xamarin.iOS
            4. Xamarin.Android
            5. Xamarin.Forms
          3. Architectural patterns
            1. MVC
              1. iOS app architecture
            2. MVVM
              1. Windows Runtime
              2. MVVM on Xamarin.iOS and Xamarin.Android
              3. MVVM with Xamarin.Forms
          4. Summary
        10. 10. ALM – Developers and QA
          1. Development pipeline
          2. Troubleshooting and diagnostics
          3. Unit testing
            1. Platform-agnostic unit tests
            2. Platform-specific unit tests
          4. UI testing
            1. Xamarin.UITests and Xamarin Test Cloud
            2. Xamarin Test Recorder
            3. Coded UI tests (Windows Phone)
            4. Calabash
          5. Summary
        11. 11. ALM – Project and Release Management
          1. Source control
            1. TFVC
            2. Git
            3. TFS/Git scenarios
              1. Git bridge
              2. NuGet packages
            4. Subversion (SVN)
          2. Continuous integration
            1. Visual Studio Team Services
            2. TeamCity
            3. Other
          3. Automated testing
          4. Beta deployment
            1. HockeyApp
            2. Crashlytics
            3. TestFlight
            4. Package distribution
          5. Live telemetry
            1. Xamarin Insights
            2. Application Insights
          6. Summary
        12. 12. ALM – App Stores and Publishing
          1. Release packages
            1. Xamarin.Android app package (.apk)
              1. Disabling debugging
              2. Linking
              3. Packing options
              4. Packaging
            2. Xamarin.iOS app bundle (.ipa)
              1. Build options
              2. Linking
              3. Provisioning profile
            3. Windows Phone app package (.appx)
          2. Distribution options
            1. App store(s)
            2. Ad-hoc
          3. Line of Business apps
            1. Private channel distribution (Android)
            2. Apple Developer Enterprise Program
            3. Windows Phone private distribution
          4. Summary
      9. A. Bibliography
      10. Index