Book Image

Xamarin Essentials

By : Mark Reynolds
Book Image

Xamarin Essentials

By: Mark Reynolds

Overview of this book

<p>Xamarin is a Mono-based suite of products that allows developers to create iOS and Android apps using C# and .NET.</p> <p>This learning guide is your first port of call to quickly learn Xamarin. Starting with the foundations by understanding the architecture behind Xamarin.iOS and Xamarin.Android, you will be guided through creating your first Xamarin.iOS and Xamarin.Android applications. In addition, you will learn how to utilize frameworks such as MvvmCross and Xamarin.Forms to increase the amount of code reuse. To conclude your journey, you will be shown how to develop your own Xamarin apps for distribution.</p> <p>Xamarin Essentials is the guide to use in order to quickly gain practical working knowledge of developing robust commercial mobile apps using C# and sharing large portions of your code base across iOS and Android apps.</p>
Table of Contents (17 chapters)
Xamarin Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Mobile applications have revolutionized the way we communicate and interact with each other, and their development is now beginning to reach a certain level of maturity. To support the development of mobile apps, there are now many tools and environments available.

Xamarin is a toolset that has seen increasing success in recent years and is gaining more and more interest, particularly from development shops that have a significant investment in .NET and C# resources. Xamarin wraps each platform's native APIs with a C# wrapper, allowing the developer to interact with the environment in essentially the same way as any native developer would. As Xamarin apps are developed in C#, a whole new possibility of sharing code across platforms comes into play with all the associated benefits and challenges.

As companies look to adopt Xamarin, new Xamarin developers will be required; where do they come from? In many cases, there will be existing seasoned mobile developers who are already familiar with Android and iOS development.

That's where this book comes in; the idea being to provide a quick path for developers already familiar with Android and/or iOS development so they can get up to speed with Xamarin development. To that end, this book does not focus on the basics of developing Android and iOS apps; rather, we focus on teaching experienced Android and iOS developers how to develop apps using Mono, C#, and the Xamarin suite of tools. Specifically, we focus on the following topics:

  • Architecture: This explains how the Xamarin products allow the use of Mono and C# to develop Android and iOS apps

  • Tools: This describes the tools provided to support the development of applications

  • Code sharing: This explains the types of code that can be shared between Android and iOS apps and the issues that might arise

  • Distribution: This explains the special considerations that should be made when distributing Xamarin.Android and Xamarin.iOS apps

It should be noted that sample apps and code snippets are provided where appropriate.

When I first started using C# to develop iOS apps, it just felt a little strange. I was no fan of Objective-C, but when did C# become the cross-platform tool of choice? I always had a lot of respect for what the Mono team accomplished, but I generally had the view that Microsoft would eventually prohibit C# and .NET from being terribly successful on any platform that they did not own. Being a Star Wars fan, and somewhat of a geek, I was reminded of a conversation from Episode III. If you recall a certain scene between Anakin and Palpatine, where Anakin realizes Palpatine knew the dark side of the force; just replace the dark side of the force with Xamarin and you get Palpatine turning to you saying: "Xamarin is a pathway to many abilities some consider to be unnatural." That's pretty much the feeling I had; was I selling out to learn a cross-platform set of technologies that would eventually completely tie me to Windows?

Two years later, I feel fairly comfortable answering that question as no! Obviously, we work in a dynamic industry and things can change in an instant, but the technology world is in a different place than it was 10 years ago, and cross-platform C# and .NET seem to play in Microsoft's favor now. So, the strange feeling has been diminished with success, and seeing how the relationship between Microsoft and Xamarin has only gone from strength to strength, I am encouraged.

If you are coming from an Objective-C or Java background, you will likely have the same feelings from time to time, but if you give the tools a chance I think you will be amazed.

I hope that you find this book a valuable resource on your path to becoming a productive mobile application developer with the Xamarin suite of products.

What this book covers

Chapter 1, Xamarin and Mono – a Pathway to the Unnatural, provides an overview of the Mono project and the suite of Mono-based commercial products offered by Xamarin.

Chapter 2, Demystifying Xamarin.iOS, describes how Mono and the iOS platform coexist and allow developers to build iOS apps using C#.

Chapter 3, Demystifying Xamarin.Android, describes how Mono and the Android platform coexist and allow developers to build Android apps using C#.

Chapter 4, Developing Your First iOS App with Xamarin.iOS, walks you through the process of creating, compiling, running, and debugging a simple iOS app.

Chapter 5, Developing Your First Android App with Xamarin.Android, walks you through the process of creating, compiling, running, and debugging a simple Android app.

Chapter 6, The Sharing Game, presents various approaches of sharing code between Xamarin.iOS and Xamarin.Android apps.

Chapter 7, Sharing with MvvmCross, walks you through the use of the Xamarin.Mobile app, which provides a cross-platform API to access location services, contacts, and the device camera.

Chapter 8, Sharing with Xamarin.Forms, walks you through the basics of using the MvvmCross framework to increase code reuse between platforms.

Chapter 9, Preparing Xamarin.iOS Apps for Distribution, discusses various methods of distributing iOS apps, and walks you through the process of preparing a Xamarin.iOS app for distribution.

Chapter 10, Preparing Xamarin.Android Apps for Distribution, discusses various methods of distributing Android apps, and walks you through the process of preparing a Xamarin.Android app for distribution.

What you need for this book

This book contains both Android and iOS examples. The simplest configuration to create and run all the examples is to have an Intel-based Mac running OS X 10.8 (Mountain Lion) or a later version with Xcode, the iOS SDK 7.x, and Xamarin installed. The 30-day trial edition of Xamarin can be used as it installs both Xamarin.iOS and Xamarin.Android by default.

The following points provide detailed requirements based on specific features and configurations.

To create and execute the iOS examples in this book, you will need the following:

  • An Intel-based Mac running OS X 10.8 (Mountain Lion) or a higher version

  • Xcode and the iOS SDK 7 or a newer version installed

  • Xamarin.iOS installed; the 30-day trial edition can be used

  • An iPad or iPhone can be helpful, but is not essential

To use the Visual Studio plugin for Xamarin.iOS, you will need the following:

  • A PC running Windows 7 or a higher version

  • Visual Studio 2010, 2012, or 2013 installed; any non-Express edition

  • Xamarin.iOS installed; the 30-day trial edition can be used

  • Network connectivity to a Mac, which meets the requirements for compiling and running the apps

To create and execute the iOS examples in this book, you will need the following:

  • A PC running Windows 7 or a higher version, or an Intel-based Mac running OS.X 10.8 (Mountain Lion) or a higher version

  • Xamarin.Android installed; the 30-day trial edition can be used. Xamarin.Android includes the Android SDK

  • An Android phone or tablet can be helpful, but is not essential

To use the Visual Studio plugin for Xamarin.Android you will need the following:

  • A PC running Windows 7 or a higher version

  • Visual Studio 2010, 2012, or 2013; any non-Express edition

  • Xamarin.Android installed; the 30-day trial edition can be used. Xamarin.Android includes the Android SDK

Who this book is for

This book is a great resource for mobile developers who are already familiar with Android and/or iOS development and need to get up to speed with Xamarin development quickly. It is assumed that you have a background of Android, iOS and C#. The book provides an overview of the Xamarin architecture, walks you through the process of creating and running sample apps, demonstrates the use of tools provided by Xamarin, and discusses special considerations for preparing apps for distribution.

Conventions

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

Code words in text are shown as follows: "Set a breakpoint on the SetContentView() statement."

A block of code is set as follows:

protected string GetFilename()
{
  return Path.Combine (
       Environment.GetFolderPath(
           Environment.SpecialFolder.MyDocuments),
          "NationalParks.json");
}

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "From the Project menu, select Publish Android Project."

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 may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title through the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail .

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 on 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 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 files e-mailed directly to you.

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 would 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/support, 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.

Piracy

Piracy of copyright 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 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

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.