Developing C# Apps for iPhone and iPad Using MonoTouch

secrettownpanamanianΚινητά – Ασύρματες Τεχνολογίες

10 Δεκ 2013 (πριν από 3 χρόνια και 10 μήνες)

100 εμφανίσεις

i
Developing C# Apps for
iPhone and iPad Using
MonoTouch
iOS Apps Development for .NET
Developers




■ ■ ■
Bryan Costanich

Developing C# Apps for iPhone and iPad Using MonoTouch: iOS Apps Development for
.NET Developers
Copyright © 2011 by Bryan Costanich
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any
means, electronic or mechanical, including photocopying, recording, or by any information
storage or retrieval system, without the prior written permission of the copyright owner and the
publisher.
ISBN-13 (pbk): 978-1-4302-3174-5
ISBN-13 (electronic): 978-1-4302-3175-2
Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image we use the names, logos,
and images only in an editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of opinion as to whether or not
they are subject to proprietary rights.
President and Publisher: Paul Manning
Lead Editor: Steve Anglin
Development Editor: Matthew Moodie
Technical Reviewer: Geoff Norton
Editorial Board:
Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Jonathan
Gennick, Jonathan Hassell, Michelle Lowman, James Markham, Matthew Moodie,
Jeff Olson, Jeffrey Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke,
Dominic Shakeshaft, Matt Wade, Tom Welsh

Coordinating Editor: Adam Heath
Copy Editor: Tracy Brown
Compositor: MacPS, LLC
Indexer: BIM Indexing & Proofreading Services
Artist: April Milne
Cover Designer: Anna Ishchenko
Distributed to the book trade worldwide by Springer Science+Business Media, LLC., 233 Spring
Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail
orders-ny@springer-sbm.com, or visit www.springeronline.com.
For information on translations, please e-mail rights@apress.com, or visit www.apress.com.
Apress and friends of ED books may be purchased in bulk for academic, corporate, or
promotional use. eBook versions and licenses are also available for most titles. For more
information, reference our Special Bulk Sales–eBook Licensing web page at
www.apress.com/bulk-sales.
The information in this book is distributed on an “as is” basis, without warranty. Although every
precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall
have any liability to any person or entity with respect to any loss or damage caused or alleged to
be caused directly or indirectly by the information contained in this work.
The source code for this book is available to readers at www.apress.com. You will need to answer
questions pertaining to this book in order to successfully download the code.
Life is a beautiful mess. Laugh or cry; choose one.

iv

Contents at a Glance
Contents .............................................................................................................. v
About the Author ............................................................................................... xiv
About the Technical Reviewer ........................................................................... xv
Acknowledgments ............................................................................................ xvi
Preface ............................................................................................................ xvii￿

Chapter 1: Getting Started with MonoTouch ................................................... 1￿

Chapter 2: Our First Application .................................................................... 11￿

Chapter 3: Creating Multi-Screen Applications Using the MVC Pattern ........ 43￿

Chapter 4: iPad and Universal (iPhone/iPad) Applications ........................... 59￿

Chapter 5: More on Views and Controllers .................................................... 73￿

Chapter 6: Introduction to Controls ............................................................... 93￿

Chapter 7: Standard Controls ...................................................................... 107￿

Chapter 8: Content Controls ........................................................................ 155￿

Chapter 9: Working with Tables .................................................................. 193￿

Chapter 10: Working with Keyboards .......................................................... 223￿

Chapter 11: Multitasking ............................................................................. 233￿

Chapter 12: Working with Touch ................................................................. 247￿

Chapter 13: Working with Shared Resources .............................................. 271￿

Chapter 14: User and Application Settings .................................................. 303￿

Chapter 15: Working with CoreLocation ...................................................... 321￿

Chapter 16: Drawing with CoreGraphics ..................................................... 331￿

Chapter 17: Core Animation ........................................................................ 361￿

Chapter 18: Notifications ............................................................................. 377￿

Chapter 19: Working with Data ................................................................... 393￿

Chapter 20: Publishing to the App Store ..................................................... 407￿

Chapter 21: Third-Party Libraries ................................................................ 419￿

Chapter 22: Using Objective-C Libraries and Code ...................................... 433￿
Index ............................................................................................................... 463

v

Contents
Contents at a Glance .......................................................................................... iv￿
About the Author ............................................................................................... xiv￿
About the Technical Reviewer ........................................................................... xv￿
Acknowledgments ............................................................................................ xvi￿
Preface ............................................................................................................ xvii￿


Chapter 1: Getting Started with MonoTouch ................................................... 1￿
Developing for the iPhone and iPad ........................................................................................................................ 2
￿
Limited Multitasking .......................................................................................................................................... 2
￿
Limited System Resources ................................................................................................................................ 2
￿
Small Screen Size .............................................................................................................................................. 3
￿
Device-specific Technology ............................................................................................................................... 3
￿
Constrained Response Time .............................................................................................................................. 3
￿
Constrained Access ........................................................................................................................................... 3
￿
MonoTouch Background ......................................................................................................................................... 4
￿
iPhone vs. iPod Touch vs iPad? ......................................................................................................................... 4
￿
How Does It Work? ............................................................................................................................................. 4
￿
How Do I Build a User-Interface (UI); Can I Use Silverlight? .............................................................................. 4
￿
How Do I Distribute My Apps? ........................................................................................................................... 5
￿
What Is the Licensing Model? ............................................................................................................................ 5
￿
Are There Any Limitations of MonoTouch? ........................................................................................................ 6
￿
Getting Started ........................................................................................................................................................ 7
￿
Mac Computer Running Snow Leopard ............................................................................................................. 7
￿
Apple’s iOS SDK ................................................................................................................................................. 7
￿
Mono for OSX ..................................................................................................................................................... 7
￿
MonoTouch SDK ................................................................................................................................................. 8
￿
Text Editor or Integrated Development Environment ......................................................................................... 8
￿
Documentation ................................................................................................................................................... 8
￿
Resources .......................................................................................................................................................... 9
￿
3
rd
Party Libraries ............................................................................................................................................... 9
￿
Summary ................................................................................................................................................................ 9
￿
■ CONTENTS
vi

Chapter 2: Our First Application .................................................................... 11￿
Starting the Example ............................................................................................................................................ 11
￿
Create a New Solution ..................................................................................................................................... 13
￿
Examining the Code ......................................................................................................................................... 15
￿
Interface Builder ................................................................................................................................................... 16
￿
Exploring Interface Builder .............................................................................................................................. 17
￿
Building the Interface ....................................................................................................................................... 22
￿
Outlets ................................................................................................................................................................... 23
￿
Outlets Exposed to Code .................................................................................................................................. 27
￿
Running the Application ................................................................................................................................... 30
￿
Actions .................................................................................................................................................................. 32
￿
Adding an Action .............................................................................................................................................. 32
￿
Actions in Code ................................................................................................................................................ 34
￿
Choosing Which Device to Simulate ..................................................................................................................... 35
￿
Application Name and Icons ................................................................................................................................. 37
￿
Application Name ............................................................................................................................................. 38
￿
Application Icons .............................................................................................................................................. 39
￿
Summary .............................................................................................................................................................. 42
￿

Chapter 3: Creating Multi-Screen Applications Using the MVC Pattern ........ 43￿
Model-View-Controller (MVC) Pattern ................................................................................................................... 43
￿
Model ............................................................................................................................................................... 44
￿
View ................................................................................................................................................................. 44
￿
Controller ......................................................................................................................................................... 45
￿
Benefits of the MVC Pattern .................................................................................................................................. 45
￿
Views and View Controllers in MonoTouch ........................................................................................................... 45
￿
Sample Application ............................................................................................................................................... 47
￿
Adding the Navigation Controller to the Main Screen ...................................................................................... 48
￿
HelloWorld and HelloUniverse Screens ............................................................................................................ 51
￿
Showing Different Screens .............................................................................................................................. 53
￿
Summary .............................................................................................................................................................. 57
￿

Chapter 4: iPad and Universal (iPhone/iPad) Applications ........................... 59￿
A Note About Resolution on the iPhone ................................................................................................................ 60
￿
Creating an iPad-Only Application ........................................................................................................................ 60
￿
Changing Common Settings in MonoDevelop .................................................................................................. 61
￿
iPad Screens in Interface Builder .................................................................................................................... 62
￿
Creating a Universal iPhone/iPad Application ....................................................................................................... 64
￿
Method 1: Universal Project Template ............................................................................................................. 65
￿
Method 2: Programmatic Device Detection ..................................................................................................... 67
￿
Summary .............................................................................................................................................................. 72
￿

Chapter 5: More on Views and Controllers .................................................... 73￿
Custom UIViewController and UIView Implementations ........................................................................................ 73
￿
Default UIView Constructor for a View Defined in a xib file ............................................................................. 74
￿
Manually Loading a UIView Defined in a .xib File ............................................................................................ 75
￿
UIViewController Event Lifecycle ..................................................................................................................... 75
￿
UIView Event Lifecycle ..................................................................................................................................... 77
￿
Managing More than One View in a Controller ..................................................................................................... 78
￿
Switching Views .............................................................................................................................................. 78
￿
■ CONTENTS
vii
Animating the Transition .................................................................................................................................. 80
￿
Handling Rotation ................................................................................................................................................. 80
￿
Rotation Lifecycle Events in UIViewController ................................................................................................. 83
￿
General Approaches to Rotation ...................................................................................................................... 84
￿
Rotation Review ............................................................................................................................................... 91
￿
Summary .............................................................................................................................................................. 91
￿

Chapter 6: Introduction to Controls ............................................................... 93￿
Coordinate System ................................................................................................................................................ 93
￿
Frame ............................................................................................................................................................... 95
￿
Autosizing ............................................................................................................................................................. 95
￿
Working with Fonts ............................................................................................................................................... 96
￿
Font Sizes ........................................................................................................................................................ 97
￿
Enumerating Fonts ........................................................................................................................................... 97
￿
Tags ...................................................................................................................................................................... 98
￿
Control States ....................................................................................................................................................... 98
￿
Working with Images ............................................................................................................................................ 99
￿
FromFile vs. FromBundle ............................................................................................................................... 100
￿
Which One? .................................................................................................................................................... 102
￿
Subclassing (Creating Custom Controls) ............................................................................................................. 102
￿
Necessary Constructors ................................................................................................................................. 102
￿
Registering Your Controls .............................................................................................................................. 102
￿
Using Your Controls in Interface Builder ........................................................................................................ 103
￿
Prototypes vs. Delegates vs. Events, What? ....................................................................................................... 103
￿
Protocols ........................................................................................................................................................ 104
￿
Delegates ....................................................................................................................................................... 104
￿
Weak-Delegates ............................................................................................................................................. 105
￿
Updating Your Controls from the UI Thread ........................................................................................................ 105
￿
Summary ............................................................................................................................................................ 106
￿

Chapter 7: Standard Controls ...................................................................... 107￿
UILabel ................................................................................................................................................................ 108
￿
Text Wrapping Options ................................................................................................................................... 109
￿
UITextField ..................................................................................................................................................... 109
￿
Borders .......................................................................................................................................................... 110
￿
Text Value ...................................................................................................................................................... 111
￿
Default Placeholder Text ................................................................................................................................ 111
￿
Keyboards ...................................................................................................................................................... 111
￿
UIButton .............................................................................................................................................................. 111
￿
Handling ‘Clicks’ ............................................................................................................................................ 111
￿
Different Types of Buttons ............................................................................................................................. 112
￿
Button Text ..................................................................................................................................................... 113
￿
UIImage ............................................................................................................................................................... 113
￿
Animating an Image View .............................................................................................................................. 115
￿
UIScrollView ........................................................................................................................................................ 115
￿
Zooming ......................................................................................................................................................... 116
￿
Implementing Tap-to-Zoom ........................................................................................................................... 117
￿
Scroll Paging .................................................................................................................................................. 117
￿
UISegmentedControl ........................................................................................................................................... 118
￿
■ CONTENTS
viii
Configuring the Segmented Control ............................................................................................................... 119
￿
Specifying Segment Sizes ............................................................................................................................. 119
￿
Handling Button Presses ................................................................................................................................ 120
￿
UISwitch .............................................................................................................................................................. 120
￿
UISlider ............................................................................................................................................................... 121
￿
Images ........................................................................................................................................................... 122
￿
Accessing the Value ....................................................................................................................................... 122
￿
UIActivityIndicatorView ....................................................................................................................................... 122
￿
UIProgressView ................................................................................................................................................... 124
￿
Setting the Progress Value ............................................................................................................................ 125
￿
UIPagerControl .................................................................................................................................................... 125
￿
Page Changes via the Pager Control .............................................................................................................. 126
￿
Updating the Pager Control When the Page is Scrolled to Via a Scroll View ................................................. 127
￿
UIAlertView ......................................................................................................................................................... 128
￿
Alerts and Garbage Collection ........................................................................................................................ 129
￿
Working with Buttons .................................................................................................................................... 129
￿
Alert Delegate ................................................................................................................................................ 131
￿
Customizing the Alert View Even Further ....................................................................................................... 132
￿
UIActionSheet ..................................................................................................................................................... 134
￿
Creating a Simple Action Sheet ..................................................................................................................... 136
￿
Button Types .................................................................................................................................................. 137
￿
Adding Custom Buttons ................................................................................................................................. 137
￿
Displaying an Action Sheet ............................................................................................................................ 138
￿
Subclassing ................................................................................................................................................... 138
￿
UIDatePicker ....................................................................................................................................................... 138
￿
Configuration ................................................................................................................................................. 140
￿
Showing Dynamically ..................................................................................................................................... 140
￿
UIPickerView ....................................................................................................................................................... 144
￿
Populating the Picker ..................................................................................................................................... 144
￿
UIPickerViewModel ........................................................................................................................................ 145
￿
UIToolbar ............................................................................................................................................................. 147
￿
Item Types ..................................................................................................................................................... 148
￿
Toolbars in Interface Builder .......................................................................................................................... 149
￿
Programmatic Creation .................................................................................................................................. 153
￿
Sizing ............................................................................................................................................................. 153
￿
Handling Clicks .............................................................................................................................................. 154
￿
Summary ............................................................................................................................................................ 154
￿

Chapter 8: Content Controls ........................................................................ 155￿
Navigation Controller .......................................................................................................................................... 155
￿
Parts of the Navigation Controller .................................................................................................................. 156
￿
Using the Navigation Controller ..................................................................................................................... 158
￿
Modifying the Navigation Bar ......................................................................................................................... 159
￿
Navigation Toolbar ......................................................................................................................................... 162
￿
Tab Bar Controller ............................................................................................................................................... 163
￿
Creating a Tab Bar Controller ......................................................................................................................... 165
￿
Split View Controller ........................................................................................................................................... 168
￿
Using the Split View ....................................................................................................................................... 170
￿
Web View ............................................................................................................................................................ 172
￿
■ CONTENTS
ix
Using the Web View ....................................................................................................................................... 173
￿
Loading Local Content ................................................................................................................................... 176
￿
Interacting with Page Content ....................................................................................................................... 176
￿
Loading Non-Web Documents ....................................................................................................................... 178
￿
Map View ............................................................................................................................................................ 178
￿
Using the Map View ....................................................................................................................................... 179
￿
Using Device Location .................................................................................................................................... 181
￿
Annotating the Map ........................................................................................................................................ 182
￿
User Overlays ................................................................................................................................................. 188
￿
Search Bar .......................................................................................................................................................... 191
￿
Summary ............................................................................................................................................................ 192
￿

Chapter 9: Working with Tables .................................................................. 193￿
Parts of the UITableView ..................................................................................................................................... 193
￿
Populating a Table .............................................................................................................................................. 194
￿
UITableViewSource ........................................................................................................................................ 195
￿
Responding to User Interaction ........................................................................................................................... 198
￿
UITableViewController ......................................................................................................................................... 199
￿
Refreshing the Table When Data Changes .......................................................................................................... 200
￿
Customizing the Appearance of a Table View ..................................................................................................... 200
￿
Table Styles ................................................................................................................................................... 200
￿
Providing a Table Index .................................................................................................................................. 202
￿
Cell Styles ...................................................................................................................................................... 204
￿
Custom Cells .................................................................................................................................................. 206
￿
Editable Tables ................................................................................................................................................... 212
￿
Editing Methods ............................................................................................................................................. 213
￿
Deleting Items ................................................................................................................................................ 215
￿
Advanced Table Editing ................................................................................................................................. 216
￿
Table Performance Considerations ..................................................................................................................... 218
￿
Cell Reuse ...................................................................................................................................................... 219
￿
Cache the Row Height .................................................................................................................................... 219
￿
Cache Images ................................................................................................................................................ 219
￿
Avoid Transparency ....................................................................................................................................... 220
￿
Manually Draw the Cell .................................................................................................................................. 220
￿
Avoid Complex Graphical Computations ........................................................................................................ 220
￿
Create Your Cell in Code ................................................................................................................................ 220
￿
Further Optimizations .................................................................................................................................... 220
￿
Summary ............................................................................................................................................................ 221
￿

Chapter 10: Working with Keyboards .......................................................... 223￿
Keyboard/Input Properties .................................................................................................................................. 223
￿
Capitalization ................................................................................................................................................. 224
￿
Correction ...................................................................................................................................................... 224
￿
Keyboard ........................................................................................................................................................ 225
￿
Return Key ..................................................................................................................................................... 226
￿
Languages ..................................................................................................................................................... 227
￿
Hiding the Keyboard ............................................................................................................................................ 227
￿
Making Input Fields Visible When the Keyboard Covers Them ........................................................................... 228
￿
Summary ............................................................................................................................................................ 231
￿
■ CONTENTS
x

Chapter 11: Multitasking ............................................................................. 233￿
Application States ............................................................................................................................................... 234
￿
Understanding Background Tasks ...................................................................................................................... 235
￿
Checking for Multitasking Capability ............................................................................................................. 236
￿
Application Delegate Methods ....................................................................................................................... 236
￿
Multitasking Guidelines and Requirements ................................................................................................... 237
￿
Asking the iOS for Time to Complete a Task ....................................................................................................... 239
￿
Task Execution Expiration Time ..................................................................................................................... 239
￿
Task Completion Patterns .............................................................................................................................. 240
￿
Registering Your Application to be Allowed to Perform a Particular Background Task Category ....................... 241
￿
Audio Applications .............................................................................................................................................. 243
￿
Location Applications .......................................................................................................................................... 243
￿
VoIP Applications ................................................................................................................................................ 244
￿
VoIP Socket Handling ..................................................................................................................................... 244
￿
VoIP Keep-alive .............................................................................................................................................. 244
￿
Summary ............................................................................................................................................................ 245
￿

Chapter 12: Working with Touch ................................................................. 247￿
When to Use Which? ........................................................................................................................................... 247
￿
Enabling Touch ................................................................................................................................................... 248
￿
Touch Events ...................................................................................................................................................... 249
￿
The UITouch Class .......................................................................................................................................... 249
￿
Using Touch Events ........................................................................................................................................ 249
￿
Gesture Recognizers ........................................................................................................................................... 255
￿
Using Gesture Recognizers ............................................................................................................................ 255
￿
Retrieving Gesture Information ...................................................................................................................... 259
￿
Example Using the Tap Gesture ..................................................................................................................... 262
￿
Example Using the Pan Gesture to Drag an Object ........................................................................................ 262
￿
Allowing Gestures and Touch Events Simultaneously ................................................................................... 265
￿
Creating a Custom Gesture ............................................................................................................................ 265
￿
Summary ............................................................................................................................................................ 269
￿

Chapter 13: Working with Shared Resources .............................................. 271￿
File System ......................................................................................................................................................... 271
￿
Case-Sensitivity ............................................................................................................................................. 271
￿
Application Sandbox ...................................................................................................................................... 272
￿
Application Directories ................................................................................................................................... 272
￿
Backup/Restore ............................................................................................................................................. 273
￿
Application Updates ....................................................................................................................................... 274
￿
Device Battery ..................................................................................................................................................... 274
￿
Battery Level .................................................................................................................................................. 274
￿
Battery State .................................................................................................................................................. 275
￿
Getting Battery Change Notifications ............................................................................................................. 276
￿
Address Book/Contacts ....................................................................................................................................... 276
￿
Address Book Controllers .............................................................................................................................. 277
￿
Working Directly with the Address Book ....................................................................................................... 285
￿
Photos and Camera ............................................................................................................................................. 289
￿
UIImagePickerController ................................................................................................................................ 289
￿
AV Foundation Framework ............................................................................................................................. 295
￿
■ CONTENTS
xi
Network Activity Indicator ................................................................................................................................... 298
￿
Accelerometer ..................................................................................................................................................... 300
￿
Summary ............................................................................................................................................................ 302
￿

Chapter 14: User and Application Settings .................................................. 303￿
Working with Settings in the iOS ........................................................................................................................ 303
￿
Registering Settings with the Settings Application ............................................................................................. 307
￿
Creating a Settings Bundle ............................................................................................................................ 308
￿
Creating the Property List File ....................................................................................................................... 308
￿
Accessing Settings ............................................................................................................................................. 316
￿
Saving Settings ................................................................................................................................................... 316
￿
Initializing Settings ............................................................................................................................................. 316
￿
Summary ............................................................................................................................................................ 319
￿

Chapter 15: Working with CoreLocation ...................................................... 321￿
Under the Hood ................................................................................................................................................... 321
￿
Usage Pattern ..................................................................................................................................................... 322
￿
Instantiating CLLocationManager ....................................................................................................................... 322
￿
Configuring the Location Manager ...................................................................................................................... 323
￿
Update Threshold ........................................................................................................................................... 323
￿
Accuracy ........................................................................................................................................................ 323
￿
Listening for Updates .......................................................................................................................................... 324
￿
UpdatedLocation ............................................................................................................................................ 324
￿
UpdatedHeading ............................................................................................................................................ 325
￿
Starting the Location Service Updates ................................................................................................................ 326
￿
Capabilities .................................................................................................................................................... 326
￿
Stopping Updates ................................................................................................................................................ 328
￿
Battery Drain ....................................................................................................................................................... 328
￿
Summary ............................................................................................................................................................ 329
￿

Chapter 16: Drawing with CoreGraphics ..................................................... 331￿
Painter’s Model ................................................................................................................................................... 332
￿
Performance ....................................................................................................................................................... 332
￿
Colors .................................................................................................................................................................. 332
￿
A Bit o’ Color Theory ...................................................................................................................................... 332
￿
Alpha RGB ...................................................................................................................................................... 333
￿
UIColor and CGColor ....................................................................................................................................... 334
￿
Drawing Context ................................................................................................................................................. 334
￿
Drawing Onscreen ......................................................................................................................................... 335
￿
Drawing Off-Screen ....................................................................................................................................... 335
￿
CoreGraphics Coordinate System ....................................................................................................................... 338
￿
Transforming the Context Coordinate Space ................................................................................................. 342
￿
Transforming the Coordinates of Individual Drawing Operations .................................................................. 342
￿
Drawing Tools ..................................................................................................................................................... 343
￿
Paths .............................................................................................................................................................. 343
￿
Primitives ....................................................................................................................................................... 344
￿
Text ................................................................................................................................................................ 345
￿
Images ........................................................................................................................................................... 346
￿
Patterns ......................................................................................................................................................... 347
￿
Shadows ........................................................................................................................................................ 350
￿
■ CONTENTS
xii
Transformations .................................................................................................................................................. 352
￿
Hit Testing ........................................................................................................................................................... 354
￿
Updating the Drawing Surface in Real-time ....................................................................................................... 357
￿
Full View Update ............................................................................................................................................ 357
￿
Partial View Updates ...................................................................................................................................... 358
￿
Other Features of CoreGraphics .......................................................................................................................... 358
￿
Summary ............................................................................................................................................................ 359
￿

Chapter 17: Core Animation ........................................................................ 361￿
View-Based Animation Framework .................................................................................................................... 362
￿
View Animations via the Animation Blocks .................................................................................................... 362
￿
View Animations via Block-Based Animation ................................................................................................ 362
￿
Comparison of the Two Approaches .............................................................................................................. 363
￿
What Is Animatable? ...................................................................................................................................... 363
￿
Configuring Animation Behavior .................................................................................................................... 364
￿
Animation Curves ........................................................................................................................................... 366
￿
View Transitions ............................................................................................................................................ 367
￿
Specifying Behavior via Methods ................................................................................................................... 368
￿
Advanced Core Animation with Layers ............................................................................................................... 369
￿
Layer-Based Animation .................................................................................................................................. 370
￿
Layer Animation Types ................................................................................................................................... 370
￿
Summary ............................................................................................................................................................ 375
￿

Chapter 18: Notifications ............................................................................. 377￿
How Notifications Work ...................................................................................................................................... 377
￿
Scheduling Local Notifications ........................................................................................................................... 378
￿
Handling Notifications ......................................................................................................................................... 379
￿
Push Notifications ............................................................................................................................................... 381
￿
Restrictions and Limitations .......................................................................................................................... 382
￿
The Sandbox and Production Environments .................................................................................................. 382
￿
APNS-Sharp ................................................................................................................................................... 382
￿
Identifying Devices ......................................................................................................................................... 383
￿
Creating a Push Notification Certificate ......................................................................................................... 385
￿
Creating and Installing a Provisioning Profile ................................................................................................ 387
￿
Sending Push Notifications ............................................................................................................................ 390
￿
Summary ............................................................................................................................................................ 391
￿

Chapter 19: Working with Data ................................................................... 393￿
SQLite ................................................................................................................................................................. 394
￿
Limitations of SQLite ...................................................................................................................................... 394
￿
Version Matrix ................................................................................................................................................ 395
￿
Creating a Database ....................................................................................................................................... 395
￿
Backups and Data Update Strategy .................................................................................................................... 396
￿
Backups ......................................................................................................................................................... 396
￿
Application Updates ....................................................................................................................................... 397
￿
Data Access Technologies .................................................................................................................................. 398
￿
ADO.NET ......................................................................................................................................................... 398
￿
SQLite-Net ...................................................................................................................................................... 400
￿
Vici CoolStorage ............................................................................................................................................. 403
￿
NHibernate ..................................................................................................................................................... 405
￿
■ CONTENTS
xiii
Summary ............................................................................................................................................................ 406
￿

Chapter 20: Publishing to the App Store ..................................................... 407￿
Review Guideline Conformity .............................................................................................................................. 407
￿
Apple Blog ...................................................................................................................................................... 409
￿
Building for Distribution ...................................................................................................................................... 409
￿
Creating and Installing a Distribution Provisioning Profile ............................................................................. 409
￿
Adding a Distribution Build Configuration ...................................................................................................... 410
￿
Configure Distribution Bundle Signing ........................................................................................................... 411
￿
Building .......................................................................................................................................................... 412
￿
Submitting Your App via iTunes Connect ............................................................................................................ 415
￿
Application Rejection Dispute Resolution ........................................................................................................... 417
￿
Summary ............................................................................................................................................................ 418
￿

Chapter 21: Third-Party Libraries ................................................................ 419￿
MonoTouch.Dialog .............................................................................................................................................. 420
￿
DialogViewController ...................................................................................................................................... 421
￿
RootElement, Sections, and Child Elements .................................................................................................. 422
￿
Using MT.D ..................................................................................................................................................... 424
￿
LINQ Support .................................................................................................................................................. 425
￿
MonoTouch-Facebook ........................................................................................................................................ 425
￿
Three20 ............................................................................................................................................................... 428
￿
Tapku .................................................................................................................................................................. 429
￿
MonoTouch-Controls ........................................................................................................................................... 430
￿
XNATouch ........................................................................................................................................................... 431
￿
Summary ............................................................................................................................................................ 432
￿

Chapter 22: Using Objective-C Libraries and Code ...................................... 433￿
btouch ................................................................................................................................................................. 433
￿
btouch Process .............................................................................................................................................. 434
￿
A Quick Objective-C Primer ................................................................................................................................. 435
￿
Files ............................................................................................................................................................... 435
￿
Classes ........................................................................................................................................................... 435
￿
Methods/Messages ........................................................................................................................................ 436
￿
Properties ...................................................................................................................................................... 438
￿
Protocols ........................................................................................................................................................ 439
￿
Compiling the Objective-C Library ...................................................................................................................... 440
￿
Building the Tapku Library ............................................................................................................................. 441
￿
Creating API Definition File and Helper Code ................................................................................................. 445
￿
Running btouch .............................................................................................................................................. 457
￿
Adding the Compiled Objective-C Library ...................................................................................................... 457
￿
Referencing the Wrapper DLL ........................................................................................................................ 458
￿
Configuring the Build ..................................................................................................................................... 459
￿
Using the Library ............................................................................................................................................ 461
￿
Summary ............................................................................................................................................................ 462
￿
Index ............................................................................................................... 463


xiv

About the Author
Bryan Costanich

xv

About the Technical
Reviewer
Geoff Norton is a developer for Novell, working on the Mono Project. He is the lead on the
MonoTouch project and the MonoMac runtime, and is a member of the MonoDroid team. Geoff
has been a Mono Project contributor since 2004, and he is also responsible for the OSX port of the
Mono runtime.


xvi

Acknowledgments
This book would not have been possible if it weren't for the help of Geoff Norton, the product
head of MonoTouch at Novell. He served as the technical reviewer, making sure that everything
in here is as accurate as can be. My sincerest thanks to him for all his hard work.
I'd also like to thank my friends for sticking it out while I worked tirelessly on this book for
nearly a year, barely seeing them. I'm free now, so let's hang.

xvii

Preface
Thanks for purchasing Developing C# Apps for iPhone and iPad Using MonoTouch. It's been a
long time in coming, but I hope you feel it's worth the wait. The goal of this book is to not only
introduce MonoTouch, but to really give you a solid, thorough understanding of iOS
programming with it. If you go through this book, front to back, and learn the concepts and gain
an understanding of the content, you should consider yourself a well-versed iOS developer.