You are previewing Professional iPhone® Programming with MonoTouch and .NET/C#.
O'Reilly logo
Professional iPhone® Programming with MonoTouch and .NET/C#

Book Description

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.

  • Chapter 1 "Introduction to iPhone Development with MonoTouch for C# Developers" 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.

  • Chapter 2 "Introduction to MonoTouch" gives you a firm foundation in MonoTouch, MonoDevelop, Interface Builder, debugging, and deploying.

  • Chapter 3 "Planning Your App's UI: Exploring the Screen Controls" teaches you about creating your application's UI and specifically how the UI on the iPhone can differ from UIs that you might have created before. You also explore the Input & Value objects from the Interface Builder Objects Library.

  • Chapter 4 "Data Controls" shows the Interface Builder Objects Library Cocoa Touch classes for Controllers, Data Views, and Windows, Views, & Bars.

  • Chapter 5 "Working with Data on the iPhone" looks at the SQLite database engine as well as strategies to store data off the device on a central server through SOAP and REST (using XML and JSON) without tying up the user interface.

  • Chapter 6 "Displaying Data Using Tables" looks at displaying information in a table, using tables for navigation, taking advantage of UITableView's built-in editing features, and adding a search bar to a table.

  • Chapter 7 "Mapping" covers CoreLocation and MapKit, using Location Services, and adding maps and geocoding to your application.

  • Chapter 8 "Application Settings" focuses on application settings, and looks at two aspects of settings for your MonoTouch app: the Info.plist and your settings bundle. It covers what settings you might want to set in your Info.plist and why, and then looks at what code it takes to read and use the settings that you save in the settings bundle. And it also takes you through the building of the settings that you might have in a social media-type application. Going through each step, you will examine the Root.plist inside the Property List Editor and see the settings dialog that will result from it.

  • Chapter 9 "Programming with Device Hardware" covers accelerometer device orientation, and proximity detection support, networking, and developing with battery life in mind.

  • Chapter 10 "Programming with Multimedia" discussing integrating images and the image picker, watching and recording videos, playing and recording audio, and using animation

  • Chapter 11 "Talking to Other Applications" discusses the ways you can use MonoTouch to talk to other applications on the iPhone, both Apple-built applications and those downloaded from the App Store. It also provides helpful ways of accessing the iPhone's Address Book and the iPod music library.

  • Chapter 12 "Localizing for an International Audience" first defines internationalization and localization, then shows displaying translated text and images, formatting dates, times, and numbers, then extracting text for translation.

  • Chapter 13 "Programming the iPad" the capabilities of the iPad are, what new APIs and controls have been introduced that you can use in iPad-specific applications, and how to build applications that can work on both iPad and iPhone devices.

  • Chapter 14 "Just Enough Objective-C" provides you with a reference and introduction to Objective-C that will help you acquire an ability to comprehend Objective-C which is something that will come in very handy.

  • Chapter 15 "The App Store: Submitting and Marketing Your App" discusses all things App Store. First, it talks about the process that you need to go through before you are ready to submit - this includes final testing with Ad-Hoc builds and a presubmission checklist. Next it addresses actually submitting to the App Store, and then finally what to do with your app after it's in the App Store. This chapter also touches on alternative monetization strategies such as ads or in app purchases.

Table of Contents

  1. Copyright
  2. ABOUT THE AUTHORS
  3. ABOUT THE TECHNICAL EDITORS
  4. CREDITS
  5. ACKNOWLEDGMENTS
  6. FOREWORD
  7. INTRODUCTION
    1. WHO THIS BOOK IS FOR
    2. WHAT THIS BOOK COVERS
    3. HOW THIS BOOK IS STRUCTURED
    4. WHAT YOU NEED TO USE THIS BOOK
    5. CONVENTIONS
    6. SOURCE CODE
    7. ERRATA
    8. P2P.WROX.COM
  8. 1. Introduction to iPhone Development with MonoTouch for C# Developers
    1. 1.1. PRODUCT COMPARISON
      1. 1.1.1. .NET Framework
      2. 1.1.2. Mono
      3. 1.1.3. MonoTouch
        1. 1.1.3.1. MonoTouch Components
        2. 1.1.3.2. Namespaces and Classes
      4. 1.1.4. MonoDevelop
      5. 1.1.5. iPhone
    2. 1.2. MOBILE DEVELOPMENT
    3. 1.3. APPLE IPHONE SDK TOOLS
      1. 1.3.1. Tools
      2. 1.3.2. Licensing
    4. 1.4. SUMMARY
  9. 2. Introduction to MonoTouch
    1. 2.1. BEFORE YOU BEGIN DEVELOPING
    2. 2.2. THE COMPONENTS OF MONOTOUCH
      1. 2.2.1. What Is Mono?
      2. 2.2.2. Namespaces and Classes of MonoTouch
    3. 2.3. WORKING WITH MONODEVELOP
    4. 2.4. USING INTERFACE BUILDER
      1. 2.4.1. Working with Library Controls
      2. 2.4.2. Setting Up Outlets
      3. 2.4.3. Setting Up Actions
    5. 2.5. HELLO WORLD WITH INTERFACE BUILDER
    6. 2.6. HELLO WORLD IN CODE
    7. 2.7. DEBUGGING
      1. 2.7.1. On the Simulator
      2. 2.7.2. On the Device
    8. 2.8. UNDERSTANDING THE LINKER
    9. 2.9. DEPLOYING YOUR APPLICATION
    10. 2.10. SUMMARY
  10. 3. Planning Your App's UI: Exploring the Screen Controls
    1. 3.1. CREATING IPHONE(Y) UI AND APPLICATION INTERACTION PATTERNS
      1. 3.1.1. Command Interfaces
      2. 3.1.2. Radio Interfaces
      3. 3.1.3. Navigation Interfaces
      4. 3.1.4. Modal Interfaces
      5. 3.1.5. Combination Interfaces
    2. 3.2. UILABEL
    3. 3.3. UIBUTTON
    4. 3.4. UITEXTFIELD
    5. 3.5. UISWITCH
    6. 3.6. UISLIDER
    7. 3.7. UIACTIVITYINDICATORVIEW
    8. 3.8. UISEGMENTEDCONTROL
    9. 3.9. UIPAGECONTROL
    10. 3.10. SUMMARY
  11. 4. Data Controls
    1. 4.1. WINDOWS AND VIEWS
      1. 4.1.1. UIWindow
      2. 4.1.2. UIView
    2. 4.2. DATA VIEW CONTROLS
      1. 4.2.1. UIWebView
        1. 4.2.1.1. Web-based Content
        2. 4.2.1.2. Local HTML Content
        3. 4.2.1.3. Other Content
      2. 4.2.2. UIScrollView
        1. 4.2.2.1. Image Scrolling
        2. 4.2.2.2. Paging
      3. 4.2.3. UITextView
        1. 4.2.3.1. Read-Only Text View
        2. 4.2.3.2. Editable Text View
      4. 4.2.4. UIPickerView
        1. 4.2.4.1. Single Component Picker
        2. 4.2.4.2. Multiple Component Picker
      5. 4.2.5. UIDatePicker
    3. 4.3. CONTROLLERS AND BARS
      1. 4.3.1. UIViewController
      2. 4.3.2. UIToolbar
      3. 4.3.3. UITabBarController
        1. 4.3.3.1. Simple TabBar
        2. 4.3.3.2. Editable TabBar
      4. 4.3.4. UINavigationController
    4. 4.4. SUMMARY
  12. 5. Working with Data on the iPhone
    1. 5.1. WORKING WITH SQLITE
      1. 5.1.1. Using Mono.Data.Sqlite
      2. 5.1.2. Setting Up a Database
      3. 5.1.3. Setting Up Tables
      4. 5.1.4. Using SQL Statements
        1. 5.1.4.1. Using Read/Select to Read Data
        2. 5.1.4.2. Using SQL Statements to Get Data
      5. 5.1.5. Upgrading Strategies
        1. 5.1.5.1. Upgrading in Place
        2. 5.1.5.2. Copying Data
        3. 5.1.5.3. Storing Data Remotely
    2. 5.2. WORKING WITH REMOTE DATA
      1. 5.2.1. Using SOAP
        1. 5.2.1.1. Working with ASMX Web Services
        2. 5.2.1.2. Working with Windows Communication Foundation (WCF)
      2. 5.2.2. Using REST-Based Web Services
        1. 5.2.2.1. Using JavaScript Object Notation (JSON)
      3. 5.2.3. Retrieving Data
        1. 5.2.3.1. Using LINQ to XML
        2. 5.2.3.2. Using Asynchronous Data Retrieval
      4. 5.2.4. Posting Data with POST
      5. 5.2.5. Using Web Services Responsibly
    3. 5.3. SUMMARY
  13. 6. Displaying Data Using Tables
    1. 6.1. DISPLAYING DATA IN A TABLE
      1. 6.1.1. Selecting a Cell
      2. 6.1.2. Changing the Cell Layout
      3. 6.1.3. Presenting Grouped Data
      4. 6.1.4. Adding an Index
      5. 6.1.5. Grouped Table Style
      6. 6.1.6. Customizing the Cell Layout
    2. 6.2. NAVIGATING WITH TABLES
      1. 6.2.1. Using UINavigationController
      2. 6.2.2. Implementing a Second Level of Navigation
      3. 6.2.3. Creating Static Row Content
    3. 6.3. EDITING TABLE ROWS
      1. 6.3.1. Adding Swipe to Delete
      2. 6.3.2. Enabling Edit "Mode"
      3. 6.3.3. Re-Ordering Cells
      4. 6.3.4. Creating an Insert Icon
      5. 6.3.5. Adding New Rows
    4. 6.4. ADDING A SEARCH BAR TO A TABLE
      1. 6.4.1. Enabling the Search Bar
      2. 6.4.2. Customizing Search Appearance
    5. 6.5. SUMMARY
  14. 7. Mapping
    1. 7.1. MAP BASICS
      1. 7.1.1. Introducing MapKit
      2. 7.1.2. Introducing CoreLocation
        1. 7.1.2.1. Location
        2. 7.1.2.2. Heading
    2. 7.2. USING CORELOCATION
      1. 7.2.1. Determining Device Location
        1. 7.2.1.1. Reverse Geocoding
      2. 7.2.2. Tracking Device Movement
    3. 7.3. USING MAPKIT
      1. 7.3.1. Showing a Map
      2. 7.3.2. Annotating the Map
        1. 7.3.2.1. Zoom Level
        2. 7.3.2.2. Functional Annotations
        3. 7.3.2.3. Colorful Annotations
        4. 7.3.2.4. Better Performing Annotations
      3. 7.3.3. Using the Geocoding Feature
    4. 7.4. SUMMARY
  15. 8. Application Settings
    1. 8.1. EXPLORING THE INFO.PLIST
      1. 8.1.1. UIStatusBarHidden
      2. 8.1.2. UIInterfaceOrientation
      3. 8.1.3. UIRequiresPersistentWiFi
      4. 8.1.4. UIPrerenderedIcon
    2. 8.2. PEEKING IN THE SETTINGS BUNDLE
      1. 8.2.1. The Settings Application
      2. 8.2.2. Adding Your App to the Settings Application
        1. 8.2.2.1. Working with the Settings Bundle
        2. 8.2.2.2. Adding a Settings Bundle to Your Project
        3. 8.2.2.3. Setting Up Your Property List
        4. 8.2.2.4. Adding a Text Field
        5. 8.2.2.5. Adding a Secure Text Field
        6. 8.2.2.6. Adding a MultiValue Field
        7. 8.2.2.7. Adding a Toggle Switch
        8. 8.2.2.8. Adding a Slider
      3. 8.2.3. Reading Your Settings
      4. 8.2.4. Updating Your Settings
    3. 8.3. SUMMARY
  16. 9. Programming with Device Hardware
    1. 9.1. RESPONDING TO ACCELERATION
      1. 9.1.1. Accelerometer
      2. 9.1.2. Using the XYZ Coordinate System
      3. 9.1.3. Coding with the Accelerometer
      4. 9.1.4. Using Acceleration for UI Input
    2. 9.2. DETERMINING DEVICE ORIENTATION
      1. 9.2.1. Beginning Notification
      2. 9.2.2. Determining Static Device Orientation
      3. 9.2.3. Determining Event-Based Orientation
    3. 9.3. READING THE PROXIMITY SENSOR
    4. 9.4. NETWORKING
    5. 9.5. TAKING BATTERY LIFE INTO ACCOUNT
      1. 9.5.1. Determining the Static Battery State
      2. 9.5.2. Using Battery Change Events
    6. 9.6. ACCESSING SYSTEM INFORMATION
    7. 9.7. MOBILE DEVELOPMENT
    8. 9.8. SUMMARY
  17. 10. Programming with Multimedia
    1. 10.1. IMAGES
      1. 10.1.1. Displaying Images
      2. 10.1.2. Picking an Image
      3. 10.1.3. Handling a Picked Image
      4. 10.1.4. Creating an Image from the Camera
      5. 10.1.5. Editing an Image
      6. 10.1.6. Customizing the Camera
      7. 10.1.7. Saving an Image to the Photo Album
    2. 10.2. VIDEO
      1. 10.2.1. Playing a Video
      2. 10.2.2. Customizing the Video Player
      3. 10.2.3. Picking a Video
      4. 10.2.4. Recording Video
      5. 10.2.5. Editing a Video
      6. 10.2.6. Saving a Video to the Saved Photo Album
    3. 10.3. AUDIO
      1. 10.3.1. Playing Audio
        1. 10.3.1.1. Short Audio
        2. 10.3.1.2. Vibration
        3. 10.3.1.3. Long Audio
      2. 10.3.2. Recording Audio
    4. 10.4. ANIMATION
      1. 10.4.1. Creating Basic Animation
      2. 10.4.2. Using UIView Animations
    5. 10.5. SUMMARY
  18. 11. Talking to Other Applications
    1. 11.1. INTEGRATING APPLE APPLICATIONS
      1. 11.1.1. Opening Up Safari
      2. 11.1.2. Opening Up E-Mail
      3. 11.1.3. Making a Telephone Call
      4. 11.1.4. Sending a Text/SMS Message
      5. 11.1.5. Opening a Location in the Maps Application
      6. 11.1.6. Opening a YouTube Video
      7. 11.1.7. Opening Up the iTunes Store and the App Store
    2. 11.2. THIRD-PARTY APPLICATION INTEGRATION
      1. 11.2.1. Simple Integration with Google Earth
      2. 11.2.2. Further Integration with Skype
    3. 11.3. ACCEPTING CALLS FROM OTHER APPLICATIONS
      1. 11.3.1. Configuring Your Info.plist File
      2. 11.3.2. Implementing an OpenURL Schema
    4. 11.4. INTEGRATING WITH THE ADDRESS BOOK
      1. 11.4.1. ABPersonViewController
      2. 11.4.2. ABPeoplePickerNavigationController
      3. 11.4.3. ABNewPersonViewController
      4. 11.4.4. ABUnknownPersonViewController
      5. 11.4.5. Handling the Selection of Properties
    5. 11.5. INTEGRATING WITH IPOD MUSIC COLLECTIONS
    6. 11.6. INTERFACING WITH OBJECTIVE-C
      1. 11.6.1. MonoTouch.Foundation
      2. 11.6.2. MonoTouch.ObjCRuntime
      3. 11.6.3. Automatic Binding to Objective-C with btouch
    7. 11.7. SUMMARY
  19. 12. Localizing for an International Audience
    1. 12.1. INTERNATIONALIZING AN APPLICATION
    2. 12.2. CHANGING LANGUAGE AND REGION SETTINGS
    3. 12.3. DISPLAYING MULTIPLE LANGUAGES
      1. 12.3.1. Showing Translated Text
        1. 12.3.1.1. Translating Buttons
      2. 12.3.2. Displaying Images
      3. 12.3.3. Localizing App Icon and Name
      4. 12.3.4. Displaying "Double Byte" Characters
      5. 12.3.5. Formatting Dates, Times, Numbers, and Currency
    4. 12.4. MANAGING LOCALIZABLE.STRINGS IN REAL-WORLD APPLICATIONS
      1. 12.4.1. genstrings
      2. 12.4.2. ngenstrings
        1. 12.4.2.1. Using ngenstrings
        2. 12.4.2.2. Limitations of ngenstrings
    5. 12.5. SUMMARY
  20. 13. Programming the iPad
    1. 13.1. THE IPAD DEVICE
    2. 13.2. WHAT MAKES AN IPAD APPLICATION?
      1. 13.2.1. Device Orientation Support
      2. 13.2.2. Startup Images
    3. 13.3. NEW IPAD FEATURES
      1. 13.3.1. Using UISplitViewController
      2. 13.3.2. Creating a Custom UIPopover
      3. 13.3.3. Displaying Modal Views
      4. 13.3.4. Recognizing Gestures
    4. 13.4. BUILDING A UNIVERSAL APP
    5. 13.5. SUMMARY
  21. 14. Just Enough Objective-C
    1. 14.1. HOW TO USE THIS CHAPTER
    2. 14.2. A BRIEF LOOK AT OBJECTIVE-C AND COCOA
    3. 14.3. ACADEMIC VERSUS PRAGMATIC APPROACHES
    4. 14.4. BASIC SYNTAX AND CONCEPTS
      1. 14.4.1. Initialization
      2. 14.4.2. Messages and Methods
      3. 14.4.3. Memory Management
    5. 14.5. CHEAT SHEETS
      1. 14.5.1. Terminology
      2. 14.5.2. Compiler Directives
      3. 14.5.3. Data Types
    6. 14.6. SUMMARY
  22. 15. The App Store: Submitting and Marketing Your App
    1. 15.1. USING AN AD-HOC BUILD FOR PRESUBMISSION TESTING
      1. 15.1.1. Getting a UDID from Your Testers
      2. 15.1.2. Making Ad-Hoc Provisioning Profiles
      3. 15.1.3. Building an Ad-Hoc Version of Your App
        1. 15.1.3.1. Adding a New Configuration for Ad-Hoc
        2. 15.1.3.2. Changing the Signing Options for the Configuration
        3. 15.1.3.3. Custom Entitlements.plist
        4. 15.1.3.4. Reviewing Bundle Settings
        5. 15.1.3.5. Building the Project
      4. 15.1.4. Packaging Your Ad-Hoc Build
        1. 15.1.4.1. The .zip Method
        2. 15.1.4.2. The .ipa Method
    2. 15.2. PREPPING FOR SUBMISSION
      1. 15.2.1. Building a Distribution Version of Your App
      2. 15.2.2. Adding a New Configuration for Distribution
      3. 15.2.3. Changing the Signing Options for the Configuration
      4. 15.2.4. Reviewing Bundle Settings
      5. 15.2.5. Building the Project
      6. 15.2.6. Presubmission Checklist
      7. 15.2.7. Submitting via iTunes Connect
    3. 15.3. PROMOTING YOUR APP
      1. 15.3.1. Supporting Your App Promotion
        1. 15.3.1.1. Your Web Site and Blog
        2. 15.3.1.2. Your Twitter Account
        3. 15.3.1.3. Your App's Facebook Page
        4. 15.3.1.4. YouTube Channel
      2. 15.3.2. Key App Promotion Techniques
        1. 15.3.2.1. Running a Contest
        2. 15.3.2.2. Starting a PR Campaign
        3. 15.3.2.3. Using In App Ads
        4. 15.3.2.4. Marketing through the Social Media Sites
    4. 15.4. SUMMARY