Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Xamarin 4.x Cross-Platform Application Development - Third Edition
Xamarin 4.x Cross-Platform Application Development - Third Edition
Xamarin 4.x Cross-Platform Application Development - Third Edition
Ebook477 pages4 hours

Xamarin 4.x Cross-Platform Application Development - Third Edition

Rating: 0 out of 5 stars

()

Read preview

About this ebook

If you are a developer with experience in C# and are just getting into mobile development, this is the book for you. This book will give you a head start with cross-platform development and will be the most useful to developers who have experience with desktop applications or the web.
LanguageEnglish
Release dateDec 26, 2016
ISBN9781786469915
Xamarin 4.x Cross-Platform Application Development - Third Edition

Related to Xamarin 4.x Cross-Platform Application Development - Third Edition

Related ebooks

Programming For You

View More

Related articles

Reviews for Xamarin 4.x Cross-Platform Application Development - Third Edition

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Xamarin 4.x Cross-Platform Application Development - Third Edition - Jonathan Peppers

    Table of Contents

    Xamarin 4.x Cross-Platform Application Development - Third Edition

    Credits

    About the Author

    About the Reviewer

    www.PacktPub.com

    Why subscribe?

    Customer Feedback

    Preface

    What this book covers

    What you need for this book

    Who this book is for

    Conventions

    Reader feedback

    Customer support

    Downloading the example code

    Downloading the color images of this book

    Errata

    Piracy

    Questions

    1. Xamarin Setup

    Understanding Xamarin

    Installing Xcode

    Installing Xamarin on Mac OS X

    Setting up the Android emulator

    Installing Xamarin on Windows

    Connecting Visual Studio to a Mac for iOS development

    Enrolling in the iOS developer program

    Registering as a Google Play developer

    Summary

    2. Hello, Platforms!

    Building your first iOS application

    Understanding Apple's MVC pattern

    Using the iOS designer

    Building your first Android application

    Understanding Android activities

    Xamarin's Android designer

    Summary

    3. Code Sharing Between iOS and Android

    Learning the MVVM design pattern

    Comparing project organization strategies

    Setting up a shared project

    Working with portable class libraries

    Using preprocessor statements

    Simplifying dependency injection

    Implementing Inversion of Control

    Summary

    4. XamSnap - A Cross-Platform App

    Starting our sample application concept

    Developing our model layer

    Writing a mock web service

    Writing the ViewModel layer

    Implementing our LoginViewModel class

    Implementing our RegisterViewModel class

    Implementing our FriendViewModel class

    Implementing our MessageViewModel class

    Writing unit tests

    Setting up a new project for unit tests

    Writing assertions

    Summary

    5. XamSnap for iOS

    Understanding the basics of an iOS app

    Xamarin.iOS Build Options

    Using UINavigationController

    Implementing the login screen

    Using segues for navigation

    Setting up UITableView

    Adding a friends list screen

    Adding a list of messages

    Composing messages

    Summary

    6. XamSnap for Android

    Introducing the Android Manifest

    Setting up Material Design

    Adding a login screen

    Using ListView and BaseAdapter

    Implementing the friends list

    Composing messages

    Summary

    7. Deploying and Testing on Devices

    iOS provisioning

    Android device settings

    Understanding the linker

    Understanding AOT compilation

    Avoiding common memory pitfalls

    Summary

    8. Contacts, Camera, and Location

    Introducing Xamarin.Mobile

    Accessing contacts

    Retrieving contacts on Android

    Looking up GPS location

    Implementing GPS location on Android

    Accessing the photo library and camera

    Accessing photos on Android

    Summary

    9. Web Services with Push Notifications

    Learning Windows Azure

    Setting up your Azure account

    Exploring Azure Functions

    Creating and calling Azure Functions

    Using HttpClient in C#

    Adding more Azure Functions

    Using the Apple Push Notification service

    Setting up your provision profile

    Setting up a certificate for push notifications

    Making client-side changes for push notifications

    Sending push notifications from the server-side

    Implementing Google Cloud Messaging

    Summary

    10. Third-Party Libraries

    The Xamarin Component Store

    Porting existing C# libraries

    Objective-C bindings

    Java bindings

    Using XPath in Java bindings

    Summary

    11. Xamarin.Forms

    Creating Hello World in Xamarin.Forms

    Understanding the architecture behind Xamarin.Forms

    Using XAML in Xamarin.Forms

    Using data-binding and MVVM

    Summary

    12. App Store Submission

    Following the iOS App Store Review Guidelines

    Submitting an app to the iOS App Store

    Creating a distribution provisioning profile

    Adding your app to iTunes Connect

    Making an iOS binary for the App Store

    Signing your Android applications

    Submitting the app to Google Play

    Google Play developer program policies

    Tips for building a successful mobile app

    Summary

    Xamarin 4.x Cross-Platform Application Development - Third Edition


    Xamarin 4.x Cross-Platform Application Development - Third Edition

    Copyright © 2016 Packt Publishing

    All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

    Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

    Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

    First published: February 2014

    Second edition: February 2015

    Third edition: December 2016

    Production reference: 1201216

    Published by Packt Publishing Ltd.

    Livery Place

    35 Livery Street

    Birmingham 

    B3 2PB, UK.

    ISBN 978-1-78646-541-2

    www.packtpub.com

    Credits

    About the Author

    Jonathan Peppers is a Xamarin MVP and lead developer on popular apps and games at Hitcents such as the Hanx Writer (for Tom Hanks) and the Draw a Stickman franchise. Jon has been working with C# for over 10 years working on a wide range of projects at Hitcents. Jon began his career working Self-Checkout software written in WinForms and later migrated to WPF. Over his career, he has worked with many .NET-centric technologies such as ASP.Net WebForms, MVC, Windows Azure, WinRT/UWP, F#, and Unity3D.

    In recent years, Hitcents has been heavily investing in mobile development with Xamarin, and has development over 50 mobile applications across multiple platforms.

    I would like to thank my wife, Amy Kate, and my son, Levi, for giving me the free time to write this book. You are both my inspiration and why I do what I do.

    About the Reviewer

    Esteban Solano Granados is a senior software engineer, Microsoft and Xamarin MVP from Cartago, Costa Rica and he enjoys learning, talk, and help others to learn about software development for the web and mobile by using his knowledge of JavaScript and C# with Xamarin, Asp.Net, NodeJS and other technologies.

    www.PacktPub.com

    For support files and downloads related to your book, please visit www.PacktPub.com.

    Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub.com for more details.

    At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

    https://www.packtpub.com/mapt

    Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career.

    Why subscribe?

    Fully searchable across every book published by Packt

    Copy and paste, print, and bookmark content

    On demand and accessible via a web browser

    Customer Feedback

    Thank you for purchasing this Packt book. We take our commitment to improving our content and products to meet your needs seriously—that's why your feedback is so valuable. Whatever your feelings about your purchase, please consider leaving a review on this book's Amazon page. Not only will this help us, more importantly it will also help others in the community to make an informed decision about the resources that they invest in to learn.

    You can also review for us on a regular basis by joining our reviewers' club. If you're interested in joining, or would like to learn more about the benefits we offer, please contact us: customerreviews@packtpub.com

    Preface

    Xamarin has built great products for developing iOS and Android applications in C#: Xamarin Studio, an addin for Visual Studio, Xamarin.iOS, and Xamarin.Android. Xamarin gives you direct access to the native APIs on each platform and the flexibility of sharing C# code.  Using Xamarin and C#, you get better productivity when compared to Java or Objective-C, and still retain great performance compared to an HTML or JavaScript solution.

     In this book, we will develop a real-world sample application to demonstrate what you can do with Xamarin technologies, and build on core platform concepts for iOS and Android. We will also cover advanced topics such as push notifications, retrieving contacts, using the camera, and GPS location. With Xamarin 3, a new framework was introduced called Xamarin.Forms. We will cover the basics of Xamarin.Forms and how you can apply it to cross-platform development. Finally, we will walkthrough what it takes to submit your application to the Apple App Store and Google Play.

    What this book covers

    Chapter 1, Xamarin Setup, is a guide for installing the appropriate Xamarin software and native SDKs for doing cross-platform development. Directs Windows users on how to connect to a Mac on their local network for doing iOS development in Visual Studio.

    Chapter 2, Hello, Platforms!, is a walkthrough of creating a simple calculator application on iOS and Android, which also covers some basic concepts on each platform.

    Chapter 3, Code Sharing  between iOS and Android, is an introduction of code sharing techniques and project setup strategies that can be used with Xamarin.

    Chapter 4, XamSnap - A Cross-Platform App, is an introduction to a sample application we will be building throughout the book. In this chapter we will write all the shared code for the application complete with unit tests.

    Chapter 5, XamSnap for iOS, shows us how to implement the iOS user interface for XamSnap and cover various iOS development concepts.

    Chapter6, XamSnap for Android, shows us how to implement the Android version of XamSnap and introduce Android-specific development concepts.

    Chapter 7, Deploying and Testing on Devices, is a walkthrough the painful process of deploying your first application to a device. We also cover why it is important to always test your application on real devices.

    Chapter 8, Contacts, Camera, and Location, introduces the library, Xamarin.Mobile, as a cross-platform way to access users’ contacts, camera, and GPS location and add these features to our XamSnap application.

    Chapter 9, Web Services with Push Notifications, shows us how to implement a real backend web service for XamSnap using Windows Azure leveraging Azure Functions and Azure Notification Hubs.

    Chapter 10, Third-Party Libraries, covers the various options of using third party libraries with Xamarin and how you can even leverage native Java and Objective-C libraries.

    Chapter 11, Xamarin.Forms, helps us discover Xamarin's latest framework, Xamarin.Forms, and how you can leverage it to build cross-platform applications.

    Chapter 12, App Store Submission, will walk us through the process of submitting your app to the Apple App Store and Google Play.

    What you need for this book

    For this book you will need a Mac computer running at least OS X 10.10. Apple requires iOS applications to be compiled on a Mac, so Xamarin has the same requirement. You can either use Xamarin Studio (best for Mac) or Visual Studio (best for Windows) as an IDE. Developers on Windows can work on iOS applications in Visual Studio by connecting to a Mac on their local network. Visit https://xamarin.com/download or https://visualstudio.com/download to download the appropriate software.

    Who this book is for

    This book is for developers that are already familiar with C# and want to learn mobile development with Xamarin. If you have worked in ASP.NET, WPF, WinRT, Windows Phone, or UWP, then you will be right at home using this book to develop native iOS and Android applications.

    Conventions

    In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

    Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: run asynchronous code in C# using the await keyword.

    A block of code is set as follows:

    class ChuckNorris

    {

        void DropKick()

        {

            Console.WriteLine(Dropkick!);

        }

    }

    When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

    class ChuckNorris

    {

        void DropKick()

        {

           

    Console.WriteLine(Dropkick!);

     

        }

    }

    Any command-line input or output is written as follows:

    # xbuild MyProject.csproj

    New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: In order to download new modules, we will go to Files | Settings | Project Name | Project Interpreter.

    Note

    Warnings or important notes appear in a box like this.

    Tip

    Tips and tricks appear like this.

    Reader feedback

    Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply e-mail feedback@packtpub.com, and mention the book's title in the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

    Customer support

    Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

    Downloading the example code

    You can download the example code files for this book 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 files e-mailed directly to you.

    You can download the code files by following these steps:

    Log in or register to our website using your e-mail address and password.

    Hover the mouse pointer on the SUPPORT tab at the top.

    Click on Code Downloads & Errata.

    Enter the name of the book in the Search box.

    Select the book for which you're looking to download the code files.

    Choose from the drop-down menu where you purchased this book from.

    Click on Code Download.

    Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

    WinRAR / 7-Zip for Windows

    Zipeg / iZip / UnRarX for Mac

    7-Zip / PeaZip for Linux

    The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Xamarin 4x-Cross-Platform-Application-Development-Third-Edition. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

    Downloading the color images of this book

    We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/Xamarin4xCrossPlatformApplicationDevelopmentThirdEdition_ColorImages.pdf.

    Errata

    Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

    To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

    Piracy

    Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

    Please contact us at copyright@packtpub.com with a link to the suspected pirated material.

    We appreciate your help in protecting our authors and our ability to bring you valuable content.

    Questions

    If you have a problem with any aspect of this book, you can contact us at questions@packtpub.com, and we will do our best to address the problem.

    Chapter 1. Xamarin Setup

    If you are reading this book, you probably already have a deep love for C#, .NET, and tools like Microsoft Visual Studio. Mobile development with the native SDKs seems daunting when you think about the work of learning a new platform, a new IDE, new application models, and perhaps a programming language or two. Xamarin aims to delight .NET developers with the tools for developing native iOS, Android, and Mac applications in C#.

    There are many advantages of choosing Xamarin to develop mobile applications instead of Java on Android and Objective-C/Swift on iOS. You can share code between both of these platforms and you can be more productive by taking advantage of the advanced language features of C# and the .NET base class libraries. Alternatively, you would have to write an entire application, twice, for both Android and iOS.

    In comparison with other techniques for developing cross-platform applications with JavaScript and HTML, Xamarin has some distinct advantages. C# is generally more performant than JavaScript, and Xamarin gives developers direct access to the native APIs on each platform. This allows Xamarin applications to have a native look and perform in a manner similar to their Java or Objective-C counterparts. Xamarin's tooling works by compiling your C# into a native ARM executable that can be packaged as an iOS or Android application. It bundles a stripped-down version of the Mono runtime with your application that only includes the features of the base class libraries your app uses.

    In this chapter, we'll set up everything you need to get started on developing with Xamarin. By the end of this chapter, we'll have all the proper SDKs and tools installed, and all the developer accounts needed for app-store submission.

    In this chapter, we will cover:

    An introduction to Xamarin tools and technology

    Installing Xcode, Apple's IDE

    Setting up all Xamarin tools and software

    Connecting Visual Studio to a Mac

    Setting up

    Enjoying the preview?
    Page 1 of 1