You are previewing iOS Development Using MonoTouch Cookbook.
O'Reilly logo
iOS Development Using MonoTouch Cookbook

Book Description

For C# and .NET developers, MonoTouch opens the door to Apple’s lucrative app store. This cookbook gives you bags of recipes to help you learn every aspect of developing for iOS. A gem of a guide.

  • Detailed examples covering every aspect of iOS development using MonoTouch and C#/.NET

  • Create fully working MonoTouch projects using step-by-step instructions.

  • Recipes for creating iOS applications meeting Apple's guidelines.

  • In Detail

    MonoTouch brings the amazing revenue opportunities of Apple’s billion dollar app store to C# and .NET developers.

    This cookbook leaves no stone unturned, providing you with practical recipes covering user interfaces, data management, multimedia , web services, and localization, right through to application deployment on the app store.

    Whatever the area of MonoTouch iOS development you need to know about, you will find a recipe for it in this cookbook. Minimum theory and maximum practical action defines this book. It is jam packed with recipes for interacting with the device hardware, like the GPS, compass and the accelerometer. Recipes for those all important real world issues such as designing the UI with the integrated designer introduced with Xcode 4. It is the essential cookbook for C# and .NET developers wanting to be part of the exciting and lucrative world of iOS development.

    Table of Contents

    1. iOS Development Using MonoTouch Cookbook
    2. Credits
    3. About the Author
    4. About the Reviewers
    5. www.PacktPub.com
      1. Support files, eBooks, discount offers and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    6. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    7. 1. Development Tools
      1. Introduction
      2. Installing pre-requisites
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Useful links
          2. Updates
        5. See also
      3. Creating an iPhone project with MonoDevelop
        1. Getting ready...
        2. How to do it...
        3. How it works...
          1. MyFirstiPhoneProjectViewController.xib
          2. MyFirstiPhoneProjectViewController.cs
          3. MyFirstiPhoneProjectViewController.designer.cs
          4. AppDelegate.cs
          5. Main.cs
          6. Info.plist
        4. There's more...
          1. List of MonoTouch assemblies
        5. See also
      4. Interface builder
        1. How to do it...
        2. How it works...
        3. There's more...
          1. More info
        4. See also
      5. Creating the UI
        1. Getting ready
        2. How to do it...
          1. Add a label
          2. Add a button
        3. How it works...
        4. There's more...
          1. Setting titles on buttons
        5. See also
      6. Accessing the UI with outlets
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Adding outlets through code
        5. See also
      7. Adding actions
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      8. Compiling
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. iPhone build options
          2. iPhone application options
        4. There's more...
          1. Linker usage
        5. See also
      9. Debugging our application
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Application performance when debugging
          2. Breakpoints in the FinishedLaunching method
        5. See also
    8. 2. User Interface: Views
      1. Introduction
      2. Adding and customizing views
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Adding views programmatically
          2. View content layout
        5. See also
      3. Receiving user input with buttons
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Creating custom buttons
        5. See also
      4. Using labels to display text
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. UILabel fonts
        5. See also
      5. Displaying images
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Using images for different screen sizes
        5. See also
      6. Displaying and editing text
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      7. Using the keyboard
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      8. Displaying progress
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      9. Displaying content larger than the screen
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. UIScrollView events
        5. See also
      10. Navigating through content divided into pages
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Proper usage of the UIPageControl
        5. See also
      11. Displaying a toolbar
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Setting a UIToolbar's items programmatically
        5. See also
      12. Creating a custom view
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
    9. 3. User Interface: View Controllers
      1. Introduction
      2. Loading a view with a view controller
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. UIViewController methods to override
        5. See also
      3. Navigating through different view controllers
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Managing navigation bar buttons
        5. See also
      4. Providing controllers in tabs
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Useful UITabBarController properties
          2. Important note on tab bar interfaces
        5. See also
      5. Creating a table controller
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. UITableViewController-specific property
        5. See also
      6. Modal view controllers
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Accessing a modal controller
            1. How many modal controllers?
        5. See also
      7. Creating a custom view controller
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Subclassing view controllers from XIBs
        5. See also
      8. Using view controllers efficiently
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      9. Combining different view controllers
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      10. iPad view controllers
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. iPad-specific controller usage
        5. See also
      11. Creating a user interface for different devices
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
    10. 4. Data Management
      1. Introduction
      2. Creating files
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Documents Folder
        5. See also
      3. Creating an SQLite database
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. SQL table creation
        5. See also
      4. Inserting and updating data
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. SQLite performance
        5. See also
      5. Querying an SQLite database
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Query performance
        5. See also
      6. Using an already existing SQLite database
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      7. Storing data with serialization
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Serializable objects
        5. See also
      8. Storing data with XML
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Deserialization
        5. See also
      9. Managing XML data with LINQ to XML
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Anonymous types in LINQ
        5. See also
    11. 5. Displaying Data
      1. Introduction
      2. Providing lists
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. More information on UIPickerView customization
          2. Date and time selection
        5. See also
      3. Displaying data in a table
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. UITableView styles
        5. See also
      4. Customizing rows
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Other useful properties of the UITableViewCell class
        5. See also
      5. Editing a table: deleting rows
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Row removal animations
        5. See also
      6. Editing a table: inserting rows
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Row re-ordering
        5. See also
      7. Table indexing
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      8. Searching through the data
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Providing search functionality to other controllers.
        5. See also
      9. Creating a simple web browser
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Scaling content
        5. See also
      10. Displaying local content
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Navigating through content
          2. UIWebView supported files
        5. See also
      11. Displaying formatted text
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Allowing specific links
        5. See also
      12. Displaying documents
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
    12. 6. Web Services
      1. Introduction
      2. Consuming web services
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. XSP shutdown
        5. See also
      3. Invoking web services
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Error handling
        5. See also
      4. Consuming WCF services
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. More information on MonoDevelop's WCF support
          2. WCF service creation
        5. See also
      5. Reading JSON data
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Serialization
        5. See also
    13. 7. Multimedia Resources
      1. Introduction
      2. Selecting images and videos
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Picking videos
        5. See also
      3. Capturing media with the camera
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Image editing
        5. See also
      4. Playing video
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Wireless streaming
        5. See also
      5. Playing music and sounds
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Playing sound files
        5. See also
      6. Recording with the microphone
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Record for a pre-defined amount of time
        5. See also
      7. Managing multiple album items directly
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Reading EXIF data
          2. Retrieving individual assets
        5. See also
    14. 8. Integrating iOS Features
      1. Introduction
      2. Starting phone calls
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. More info on OpenUrl
        5. See also
      3. Sending text messages and e-mails
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. More info on opening external applications
        5. See also
      4. Using text messaging in our application
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. SMS only
      5. Using e-mail messaging in our application
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Action sheet for drafts
        5. See also
      6. Managing the address book
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Adding a phone number to a contact
      7. Displaying contacts
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Other address book controllers
        5. See also
      8. Managing the calendar
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Info on calendars
        5. See also
    15. 9. Interacting with Device Hardware
      1. Introduction
      2. Detecting device orientation
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Device orientation and user interface orientation
        5. See also
      3. Adjusting UI orientation
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. User interface orientation on the simulator
        5. See also
      4. Proximity sensor
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Sensor support
        5. See also
      5. Retrieving battery information
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Disabling battery monitoring
        5. See also
      6. Handling motion events
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. More info motion events
        5. See also
      7. Handling touch events
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Getting the tap count
        5. See also
      8. Recognizing gestures
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Advantage of gesture recognizers
        5. See also
      9. Custom gestures
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Another usage of custom gesture recognizers
        5. See also
      10. Using the accelerometer
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Consideration using the accelerometer
        5. See also
      11. Using the gyroscope
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Determining gyroscope availability
          2. Converting radians to degrees
        5. See also
    16. 10. Location Services and Maps
      1. Introduction
      2. Determining location
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. GPS accuracy
          2. Location services availability
          3. Location services usage indicator
        5. See also
      3. Determining heading
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Magnetic versus true heading
          2. Compass availability
        5. See also
      4. Using region monitoring
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Region monitoring availability
        5. See also
      5. Using significant-change location service
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Significant-change location service availability
        5. See also
      6. Location services in the background
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Restricting to supported hardware
        5. See also
      7. Displaying maps
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Things to have in mind when using MapKit
        5. See also
      8. Geocoding
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Things to have in mind when using the MKReverseGeocoder class
        5. See also
      9. Adding map annotations
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Annotation performance
        5. See also
      10. Adding map overlays
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Creating custom overlays
          2. Standard overlay objects
        5. See also
    17. 11. Graphics and Animation
      1. Introduction
      2. Animating Views
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. UIKit animations and iOS versions
          2. Animatable properties
      3. Transforming views
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Transformation and frame
        5. See also
      4. Animation with images
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Checking for animation
        5. See also
      5. Animating layers
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Layers
        5. See also
      6. Drawing lines and curves
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Graphics context on a UIImageView
        5. See also
      7. Drawing shapes
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Transparent colors
        5. See also
      8. Drawing text
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Size of drawn text
        5. See also
      9. A simple drawing application
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Clear the drawing
        5. See also
      10. Creating an image context
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Drawing on UIImageView
          2. Background on saved drawings
        5. See also
    18. 12. Multitasking
      1. Introduction
      2. Detecting application states
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Support for multitasking
          2. Proper usage
      3. Receiving notifications for application states
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Removing notification observers
        5. See also
      4. Running code in the background
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Important considerations for background code
        5. See also
      5. Playing audio in the background
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Background state for audio
        5. See also
      6. Network connectivity maintenance
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Combining items for the UIBackgroundModes key
        5. See also
    19. 13. Localization
      1. Introduction
      2. Creating an application for different languages
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Localization in real-world application scenarios
      3. Localizable resources
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. More info on localizable resources
        5. See also
      4. Regional formatting
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
    20. 14. Deploying
      1. Introduction
      2. Creating profiles
        1. How to do it...
        2. How it works...
        3. There's more...
          1. Provisioning profiles expiration
        4. See also
      3. Creating an ad-hoc distribution bundle
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Syncing ad-hoc app bundles with iTunes
        5. See also
      4. Preparing an application for the App Store
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Lighting effect on icons
        5. See also
      5. Submitting to the App Store
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
    21. 15. iOS 5 Features
      1. Introduction
      2. Reproducing the page curl effect
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Double sided pages
      3. Styling views
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Specific properties
      4. Twitter integration
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Supporting landscape orientation
      5. Working with the split keyboard
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Problems moving the keyboard?