Professional iPhone Programming with MonoTouch and .NET/C#

Overview

What .NET C# developers need to enter the hot field of iPhone apps

iPhone applications offer a hot opportunity for developers. Until the open source MonoTouch project, this field was limited to those familiar with Apple’s programming languages. Now .NET and C# developers can join the party. Professional iPhone Programming with MonoTouch and .NET/C#is the first book to cover MonoTouch, preparing developers to take advantage of this lucrative ...

See more details below
Other sellers (Paperback)
  • All (19) from $1.99   
  • New (7) from $4.86   
  • Used (12) from $1.99   
Sending request ...

Overview

What .NET C# developers need to enter the hot field of iPhone apps

iPhone applications offer a hot opportunity for developers. Until the open source MonoTouch project, this field was limited to those familiar with Apple’s programming languages. Now .NET and C# developers can join the party. Professional iPhone Programming with MonoTouch and .NET/C#is the first book to cover MonoTouch, preparing developers to take advantage of this lucrative opportunity.

This book is for .NET developers that are interested in creating native iPhone applications written in .NET/C#. These developers want to use their existing knowledge. While .NET developers are always interested in learning, they also recognize that learning Objective-C and the specifics of the iPhone can be overwhelming. Those developers interested in MonoTouch will recognize that the cost of MonoTouch is easily made up by the ability to quickly target the iPhone using a language that they are already familiar with.

This book is designed for .NET developers that want to target the iPhone. It is designed to help you get up to speed with the iPhone, not to really teach you about the .NET Framework or C# language, which we assume you already know.

This book is designed with introductory material in Chapters 1 thru 4. You should read Chapters 1 thru 4 sequentially. These chapters introduce the MonoTouch product, the basics of developing with MonoTouch and MonoDevelop, and finally, the basics of presenting data to a user with screen and data controls and how to develop a user interface for the iPhone. Once you are comfortable with these concepts, you can typically move from one chapter to another and not necessarily have to read the chapters sequentially

Read More Show Less

Product Details

  • ISBN-13: 9780470637821
  • Publisher: Wiley
  • Publication date: 7/13/2010
  • Edition number: 1
  • Pages: 384
  • Product dimensions: 7.30 (w) x 9.10 (h) x 0.80 (d)

Meet the Author

Wallace B. McClure is a Microsoft MVP, ASPInsider, member of the national INETA Speaker's Bureau, and has a popular blog and podcast.

Martin Bowling is a software developer and marketer working with small and medium sized businesses.

Craig Dunn has worked on web technologies in corporate environments since 1993.

Chris Hardy, an ASPInsider, works at a digital agency in Manchester, UK.

Rory Blyth has worked in the software development industry for nearly a decade.

Read More Show Less

Read an Excerpt

Professional iPhone Programming with MonoTouch and .NET/C#


By Wallace B. McClure Rory Blyth Craig Dunn Chris Hardy Martin Bowling

John Wiley & Sons

Copyright © 2010 John Wiley & Sons, Ltd
All right reserved.

ISBN: 978-0-470-63782-1


Chapter One

Introduction to iPhone Development with MonoTouch for C# Developers

WHAT'S IN THIS CHAPTER?

* The history of the iPhone and its mindshare

* A short history of Mono and its relationship to the .NET Framework

* How MonoTouch opens the iPhone to .NET Developers

* Why MonoTouch is so attractive to developers

The past several years have seen an amazing growth in the use of smartphones, and USA Today recently reported how smartphones have become an indispensable part of people's lives.

Although Windows-based computers running 32-bit x86 or 64-bit x64 processors dominate the desktop computer marketplace, and the .NET Framework is the dominant development environment for the Windows platform, no single vendor or platform dominates the mobile device marketplace; devices based on Symbian, Research in Motion (Blackberry), Windows Mobile, Android, and other platforms are available. In addition, devices may run the same operating system and be presented to the user in separate form factors. This fracture in the marketplace is problematic for developers - how can they take a development framework, or tool, that they already know and use that knowledge in a device that has a large and growing market share?

This chapter looks at how the largest segment of developers can target the smartphone with the highest mindshare, and that the smartphone is growing faster in marketshare than any other device.

PRODUCT COMPARISON

This section takes a quick look at .NET Framework, Mono and MonoTouch - three products that have allowed the largest segment of developers to target the iPhone, the most exciting mobile platform currently in the marketplace.

.NET Framework

In the late 1990s, Microsoft began work on the .NET Framework. The first version of the framework shipped in 2002. Microsoft proceeded to introduce subsequent versions of the .NET Framework and has recently introduced the .NET Framework 4. The .NET Framework comes in various versions, including 32-bit versions, 64-bit versions, a version for the XBOX gaming platform, and a version for Microsoft's mobile devices referred to as the Compact Framework (CF). A few facts about .NET Framework:

* Microsoft released a development tool, Visual Studio .NET, with the Framework. This tool is the Integrated Development Environment for .NET.

* It's based on a virtual machine that executes software written for the framework. This virtual machine environment is referred to as the Common Language Runtime (CLR), and it is responsible for security, memory management, program execution, and exception handling.

* Applications written in the .NET Framework are initially compiled from source code, such as Visual Basic or C#, to an intermediate language, called MSIL. The initial compilation is performed by calling the language specific command line compiler, Visual Studio, or some other build tool. A second compilation set is typically done when an application is executed. This second compilation takes the intermediate language and compiles it into executable code that can be run on the operating system. This second compilation is referred to as just-in-time compilation.

* It's language independent, and numerous languages are available for the Framework. In the Visual Studio, Microsoft has shipped various languages including Visual Basic, F#, C++, and C#.

* It has a series of libraries that provide consistent functionality across the various languages. These libraries are referred to as the Base Class Libraries.

* Microsoft has submitted various parts of the .NET Framework to various standard organizations. Some of these are the C# language, the Common Language Infrastructure, Common Type System (CTS), Common Language Specification (CLS), and Virtual Execution System (VES).

* It has the largest number of developers for any development framework out there. As a result, more developers are familiar with the .NET Framework than any other development framework.

* A disadvantage of the .NET Framework is that it is not available for non-Microsoft platforms.

Mono

Mono is an open source project that provides a C# compiler and Common Language Runtime on non-Windows operating systems. Mono is currently licensed under GPL version 2, LGPL version 2, the MIT, and dual licenses. Mono runs on Mac, Linux, BSD, and other operating systems.

Mono was officially announced in 2001 and is the brainchild of Miguel de Icaza. Mono version 1.0 shipped in 2004, and currently Mono is at Version 2.6. Mono continues to be led by Miguel de Icaza and is under the general leadership and support of Novell.

As much as there is the desire to match the .NET Framework's features, this is not possible due to the fact that Microsoft has more resources and a head start in the development of those features. At the same time, the Mono project has parity with a large number of .NET Framework features.

Along with Mono, there is an open source IDE called MonoDevelop, which started as a port of the SharpDevelop IDE. MonoDevelop began as a project to allow for Mono development on Linux, but with the release of MonoDevelop 2.2, the ability to develop with Mono expanded to the Mac, Windows, and several other non-Linux UNIX platforms.

Though the .NET Framework is very popular, two issues make it unsuitable for running on the iPhone:

* At some level Apple and Microsoft are competitors and are likely not too excited to work together.

* The .NET Framework fundamentally is dynamically compiled at runtime. This is the just-in-time compilation of the .NET Framework. This is a violation of the Apple license and the operating principles of the iPhone OS.

Given that code running on the Microsoft .NET Framework is compiled to machine code at runtime using the just-in-time compilation, one would expect that applications written for Mono would have the same behavior and thus not be suitable for running on the iPhone. However, Mono has a technology that allows for applications to be compiled ahead of time, referred to as AOT technology.

A disadvantage of .NET/Mono and the iPhone is that .NET/Mono developers cannot take their .NET/Mono/C# knowledge and apply it to the iPhone platform. As illustrated in Figure 1-1, you see that the reason .NET/ Mono developers can't target the iPhone is because they're two separate entities.

MonoTouch

In 2009, Novell announced and shipped MonoTouch, which allows .NET developers to create native iPhone applications in C#. With MonoTouch, applications are compiled into executable code that runs on the iPhone. The significance of this should not be understated: .NET/Mono developers can target the iPhone through MonoTouch. This is illustrated in Figure 1-2.

How does MonoTouch accomplish this? Does it somehow allow Windows Forms applications to be translated or recompiled and deployed on the iPhone? MonoTouch provides a .NET layer over the native iPhone programming layer present on the iPhone OS, referred to as Cocoa Touch. Cocoa Touch is based on the Cocoa layer in the Mac OS X and is available on the iPhone, iPod Touch, and the iPad. MonoTouch does not provide a mechanism to cross-compile Windows Forms applications, but allows developers to build applications that run natively on the iPhone.

Overall, the application programming interface (API) exposed by the MonoTouch SDK is a combination of the .NET 2.0 Framework's core features, the Silverlight 2.0 API, and the APIs on the iPhone. MonoTouch provides a bridge (interop) between the iPhone's native APIs based on Objective-C and C-based APIs to the .NET world that C# developers are accustomed to.

MonoTouch Components

MonoTouch is made up of the following four components:

* The Monotouch.dll is a C# assembly that provides a binding API into the iPhone's native APIs.

* A command-line tool that compiles C# and Common Intermediate Language (CIL) code. This compiled code can then be run in the simulator or an actual iPhone.

* An add-in to MonoDevelop that allows for iPhone development and for Interface Builder to create graphical applications.

* A commercial license of the Mono runtime, which allows for the static linking of the Mono runtime with the code developed.

Namespaces and Classes

MonoTouch provides a rich set of namespaces and classes to support building applications for the iPhone. Some of the most popular namespaces and classes are:

* MonoTouch.ObjCRuntime: This namespace provides the interop/bridge between the .NET/C# world and the Objective-C world of the iPhone.

* MonoTouch.Foundation: This namespace provides support for the data types necessary to communicate with the Objective-C world of the iPhone. Most types are directly mapped. For example, the NSObject Objective-C base class is mapped to the MonoTouch.Foundation .NSObject class in C#. Some classes are not directly mapped and are instead mapped to their native .NET types. For example, NSString maps to the basic string type and NSArray maps to a strongly typed array.

* MonoTouch.UIKit: This namespace provides a direct mapping between the UI components within Cocoa Touch. The mapping is done by providing .NET classes for each UI component, and this is the namespace that developers will likely spend most of their time working with. For .NET developers, Cocoa Touch is an abstraction layer or API for building programs that run in the iPhone. Cocoa Touch is based on the Cocoa API used in building programs that run on the Mac OS X operating system. Cocoa Touch can be thought of as Cocoa tuned for the touch-based iPhone operating system.

* OpenTK: This namespace is a modified version of the OpenTK API. OpenTK is an object-oriented binding for OpenGL, which stands for the Open Graphics Library. OpenGL is an API for using three-dimensional graphics. OpenTK is a library for performing OpenGL, OpenAL, and OpenCL. It is written in C# and runs on Windows, Mac OS X, and Linux. The OpenTK implementation on the iPhone has been updated to use CoreGraphics and to only expose the functionality available on the iPhone.

In addition, MonoTouch provides a set of additional namespaces that may be important to you. These are:

* MonoTouch.AddressBook

* MonoTouch.CoreGraphics

* MonoTouch.AddressBookUI

* MonoTouch.AudioToolbox

* MonoTouch.MapKit

* MonoTouch.MediaPlayer

* MonoTouch.AVFoundation

* MonoTouch.MediaPlayer

* MonoTouch.CoreAnimation

* MonoTouch.SystemConfiguration

These namespaces are fairly self-explanatory in their functionalities and are specific to the iPhone.

MonoDevelop

MonoDevelop is a free IDE used for developing with Mono and is an early branch of the SharpDevelop IDE. Originally, MonoDevelop ran only on Linux, but with version 2.2, MonoDevelop began running on the Mac. MonoDevelop on the Mac allows for the creation and management of iPhone projects as well as debugging and deployment to the simulator and devices for testing.

iPhone

There's no doubt that Apple has changed the mobile device marketplace since the introduction of the original iPod in 2001. Although the iPod was not the first device to play mp3 files, it was the first product that played mp3 files, made it easy to use, and provided an easy-to-use marketplace to purchase audio files. The iPod really caused the mp3 device marketplace to explode.

In January 2007, Apple turned the smartphone upside down when it officially announced the first-generation iPhone. The iPhone was designed to be a smartphone that provided web browsing, e-mail, and multimedia capabilities. The first-generation iPhone connected to a wireless network and applications were delivered to the user over the mobile version of Safari.

Writing a web-based application for the iPhone is fairly simple. The Safari web browser is a great tool - it does an excellent job of scaling web-based applications to run an iPhone-sized screen. It also does well running applications that are highly dependent on JavaScript. Upgrading an iPhone web-based application is also a simple matter of deploying a new version of the application to a web server. Many applications have taken this approach.

So, the question becomes how does one write an application that fits into the iPhone?

The first-generation iPhone did not have support for users to load applications on the device. For a few users, this was not acceptable, and they began jailbreaking their iPhones, which is the process where users run software on their devices that Apple has not approved.

Jailbreaking has several problems:

* Technical Issues: Jailbreaking requires the iPhone's owner to perform the operation, and many iPhone users are not technically proficient enough to do this.

* Legality: The legality of jailbreaking is unclear at the time of this writing. It is not clear where jailbreaking falls within the Digital Millennium Copyright Act. The Electronic Frontier Foundation has asked the United States Copyright Office to recognize an exception to the DMCA that allows iPhone owners to jailbreak their devices. Apple has argued in response that jailbreaking an iPhone is a copyright violation.

* Unknowns: It comes with a series of unknowns. How well can a jailbroken iPhone be upgraded to new versions of the iPhone operating system (OS)? Will jailbreaking an iPhone open it up to security issues?

In 2008, Apple introduced the second generation of the iPhone, referred to as the iPhone 3G. With this generation and the new version of the iPhone OS, Apple released a number of enhancements, including the ability to run applications natively on the device. In addition to this, Apple has put together an ecosystem whereby users can find and install applications on their iPhone device called the App Store.

These native applications are a great improvement over web-based applications, which are limited in what they can do on a device. Fundamentally, they have to be loaded over the Web and are not able to access all device features. Native applications tend to have more support for device features like the accelerometer, file system, camera, cross-domain web services, and other features that are outside of features available in HTML and JavaScript. In addition, native applications do not depend on the wireless network to be loaded, whereas a web application is dependent on the wireless network for loading.

In 2009, Apple introduced the iPhone 3GS and version 3 of the iPhone operating system. The iPhone 3GS, a refinement of the iPhone 3G, supports higher data rates than the iPhone 3G, an improved camera, an updated CPU, and voice control.

In 2010, Apple announced and shipped the iPad. The iPad is a tablet device, and it has a larger screen than the iPhone. Also significant is that it shipped with the iPhone operating system that is fundamentally different than the iPhone.

Along with the release of each new iPhone, Apple has introduced a new iPod touch. The iPod touch can be thought of as an iPhone without the phone, camera, and support for the 3G data services; however, the iPod touch does have support for wireless networking using WiFi.

Since its availability three years ago, Apple has shipped more than 60 million units of the iPhone. The iPad is estimated to ship several million units of the iPad in its first year of availability, and this will likely result in the iPad being the most popular tablet in 2010.

Unfortunately, for developers, three issues must be considered when running on the device:

* The iPhone operating system does not allow for software code that is interpreted or dynamically compiled in any way.

* Apple's licensing for the SDK and developing with the iPhone does not allow for applications to have interpreted or dynamically compiled code.

* Apple has an extensive validation process for iPhone applications. Some of the automated tests for an application will check for dynamically compiled and interpreted code.

These issues and licensing are something that developers need to be knowledgeable of, and somewhat limit the choices that a developer has for writing applications that run on the iPhone.

(Continues...)



Excerpted from Professional iPhone Programming with MonoTouch and .NET/C# by Wallace B. McClure Rory Blyth Craig Dunn Chris Hardy Martin Bowling Copyright © 2010 by John Wiley & Sons, Ltd. Excerpted by permission.
All rights reserved. No part of this excerpt may be reproduced or reprinted without permission in writing from the publisher.
Excerpts are provided by Dial-A-Book Inc. solely for the personal use of visitors to this web site.

Read More Show Less

Table of Contents

FOREWORD.

Introduction.

Chapter 1 Introduction to iPhone Development with MonoTouch for C# Developers.

Chapter 2 Introduction to MonoTouch.

Chapter 3 Planning Your App's UI: Exploring the Screen Controls.

Chapter 4 Data Controls.

Chapter 5 Working with Data on the iPhone.

Chapter 6 Displaying Data Using Tables.

Chapter 7 Mapping.

Chapter 8 Application Settings.

Chapter 9 Programming with Device Hardware.

Chapter 10 Programming with Multimedia.

Chapter 11 Talking to Other Applications.

Chapter 12 Localizing for an International Audience.

Chapter 13 Programming the iPad.

Chapter 14 Just Enough Objective-C.

Chapter 15 The App Store: Submitting and Marketing Your App.

INDEX.

Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star

(0)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously

    If you find inappropriate content, please report it to Barnes & Noble
    Why is this product inappropriate?
    Comments (optional)