Chapter 1: The Brand New Stuff

In 2007, Steve Jobs went on stage at Macworld and proclaimed that software running on the iPhone was at least five years ahead of the competition. Since its initial release up to the time of this writing, Apple has been iterating the operating system year after year and has even added two new devices, the iPad and the Apple TV, to the list of products capable of running iOS. Over time, as the operating system was customized to run on more devices than the iPhone, it was rebranded as iOS. Now, after five years and true to the words of Steve Jobs, iOS is still the most advanced operating system around. iOS 6 takes the most advanced operating system to the next level, adding great features, including some developer-centric features like collection views, Auto Layout, and improved data privacy.

This book is about programming with iOS 6, and in this chapter, I go through the main features of iOS 6 and refer you to the chapters covering them in detail.

What’s New

Every version of iOS has introduced several key features and other minor features. The second version, iPhone OS 2, was the first to have a public SDK.

iPhone OS 3 brought Core Data from the Mac to the iPhone; other additions included Push Notifications, ExternalAccessory Kit, In App Purchases through StoreKit.framework, in app e-mail sheets, MapKit.framework that allows developers to embed Google Maps into their apps, read-only access to the iPod library, and keychain data sharing.

A minor update, 3.1, added video editor support, and another minor (yet so major) update, 3.2, added Core Text and gesture recognizers, file sharing, and PDF generation support. The 3.2 update also added a whole new product, iPad, and support for developing apps that run on iPad, as well as Universal apps that run on iPad (3.2) and iPhone (3.1.3). However, 3.2 was iPad-only and didn’t run on iPhone or iPod touch devices.

iPhone OS 4 (rebranded as iOS 4) introduced the much-awaited multitasking support, local push notifications, read-only access to calendar (EventKit.framework), blocks and Grand Central Dispatch, In app SMS sheets, and Retina display support. This version was iPhone-only and didn’t support developing apps for iPad. A minor update to this, iOS 4.2, unified iPhone and iPad operating systems.

iOS 5 introduced several important features like iCloud, Automatic Reference Counting, built-in Twitter framework, and several other minor features.

iOS 6 introduces Pass Kit, a framework which providers can use to push tickets, passes, or coupons directly to the iPhone. For example, a hotel reservation iOS app can send a confirmation of registration as a pass to the user’s iPhone.

iOS 6 also introduces a brand-new maps application for end users. To developers, there is a new SDK that allows you to show directions. You open maps by calling the method openMapsWithItems:launchOptions: on MKMapItem:

+ (BOOL)openMapsWithItems:(NSArray *)mapItems launchOptions:

     (NSDictionary *)launchOptions

However, iOS 6 doesn’t support opening maps through a URL scheme. So, you need to fall back to Google for iOS 5 devices, as illustrated in the following code fragment:

if ([[UIApplication sharedApplication] canOpenURL:

     [NSURL URLWithString:@”maps”]]) {

    // ios 6 specific

     [MKMapItem openMapsWithItems:<items> launchOptions:<options>]; } else {

    // ios 5 specific, fall back to Google

     [[UIApplication sharedApplication] openURL:

     [NSURL URLWithString:@”http://maps.google.com/<your url>”]]

}

This book focuses primarily on the new features added in iOS 6. In the next few sections, I introduce you to the key features added to iOS 6 and provide guidance for using them to push your apps to the next level.

Collection Views

Arguably the most important addition to iOS 6 is a brand-new controller for displaying and managing collection views. Collection views finally provide a way to lay out your UI elements as a grid view like the built-in Photos app or the iBooks app. You no longer have to depend on third-party grid view frameworks for creating grids or mess around with scroll views. Collection views also provide an easy way to animate content (similar to UITableView’s row animation) and to insert, delete, and reorder them. (See Chapter 7 for more on collection views.)

Auto Layout

Auto Layout is a new way to define rules that determine how elements in your user interface should be laid out. This capability was introduced in the Mac OS X SDK last year and brought to iOS with iOS 6. Auto Layout is more intuitive than the previously used “springs and struts” model and provides built-in support for mirroring UI elements for right-to-left languages. Arguably, the most important feature that Auto Layout brings in is the capability to swap strings when you localize your nib files.

Automatic Reference Counting

Though Automatic Reference Counting (ARC) was introduced with iOS 5, information about ARC and internal workings of the LLVM compiler has changed considerably, including the default storage type of properties. This edition of the book adds a whole new chapter (Chapter 5) that explains ARC, the internals of how ARC works and how to convert your code base to Objective-C ARC using the Convert to Objective-C ARC tool.

ARC is not like garbage collection offered on Mac OS X from version 10.5 (Leopard). Garbage collection is automatic memory management, whereas ARC is Automatic Reference Counting. This means that you, as a developer, don’t have to write a matching release for every retain statement. The compiler automatically inserts them for you.

ARC adds two new lifetime qualifiers, strong and weak, and also imposes certain new rules—for example, you can no longer invoke release, retain on any object. This applies to custom dealloc methods as well. When using ARC, your custom dealloc methods should release only resources (files or ports) and not instance variables. (For more on ARC, see Chapter 5.)

In App Purchases Hosted Content

iOS 6 allows you to host downloadable content for your In App Purchases with Apple. For example, if you’re making a racing game and you’re selling “cars” and “tracks” as In App Purchases, you can now host the map tiles for the tracks and the model file for the car with Apple’s servers. When the purchase is complete, you can initiate a download, all without paying a dime for hosting those files. (See Chapter 18 for information on In App Purchases and how to download hosted content.)

Social Framework

iOS 5 integrated Twitter experience right into the OS. This made sending a tweet from your app as easy as sending an e-mail using in app e-mail sheets. The framework also handled authentication for you. The Twitter framework on iOS 5 integrates with the Accounts framework to provide account authentication. In iOS 6, Apple supplanted Twitter.framework with Social.framework, which is more generic and handles other social networks like Facebook and Weibo in addition to Twitter. What this means to you as a developer is that Facebook is now tightly integrated right into the OS. So, posting to Facebook and authenticating users with Facebook is easier and doesn’t require Facebook’s official Facebook Graph SDK. However, you will still need the Graph SDK if you’re supporting iOS 5 devices. The UIKit.Framework introduces a new view controller called UIActivityViewController that is used in conjunction with the Social.framework to post content to a social network.

UI State Preservation

In iOS 3 and older operating systems, restoring the state of your UI was hard. When Apple introduced multitasking in iOS 4, apps automatically preserved and restored their state as long as they were running in the background. But low memory situations can kill your app while it’s running in the background and your app gets no notification about it. When an app was killed in the background, it wasn’t easy to restore the state of the UI, and the only way to restore the UI state was to implement a variety of hacks that developers implemented prior to iOS 4. In iOS 6, Apple made state preservation easier by providing state restoration support built into UIKit. (See Chapter 13 for more on UI state preservation.)

Other New Features

iOS 6 also introduces several other minor features including Pass Kit, increased privacy, support for interacting with Reminders, and more importantly, rich text support for UITextField.

Pass Kit

Pass Kit is a new framework that allows users to store items like coupons, boarding passes, and event tickets on their iOS devices, instead of a physical equivalent. Passes are created on the server and delivered to the user’s device, and as an iOS developer, you will not be writing code to handle them. Pass Kit, while a major feature in iOS 6, is more like APNS, heavy on the server side but little or no coding effort on the client side. As such, Pass Kit isn’t covered in this book.

Reminders

iOS 4 introduced EventKit.framework that allowed third-party apps to access a user’s calendars. In iOS 6, EventKit.framework has methods to interact with a user’s Reminders as well.

Privacy

Privacy has always been a monumental concern with apps. Prior to iOS 6, some apps, including those from high-profile social networking companies like Path, uploaded contact information to their servers without explicit consent from users. In iOS 6, access to Contacts, Photo Library (either through AssetsLibrary.framework or through UIImagePickerController), reminders, and calendars requires explicit permission from the user. This means that, if you’ve previously accessed this information, be prepared to receive empty data from the user. You can also customize why you need access to such information by setting the values for the keys NSLocationUsageDescription, NSPhotoLibraryUsageDescription, NSCalendarsUsageDescription, NSContactsUsageDescription, and NSRemindersUsageDescription in your application’s Info.plist file. You can also set the values from the UI using one of the options shown in Figure 1-1.

9781118449974-fg0101.tif

Figure 1-1 Info.plist showing the newly added Usage Description keys

Displaying Rich Text

UITextView and UITextField support NSAttributedString, and you can display rich text by creating an NSAttributedString. You create an NSAttribtedString using CoreText.framework. (See Chapter 26 for a discussion of Core Text.)

Summary

Adoption rates of iOS have always been way ahead of the competition. A couple of years ago, when iPhone OS 3.0 was launched, adoption rates were partly hindered on iPod touches because it was a $10 paid upgrade. However, Apple soon made it free, and adoption rates increased. Similarly, when Apple released iOS 4, the adoption rate was initially slow because of performance issues on older phones, namely iPhone 3G and the original iPhone (and equivalent iPod touches). Some features, mainly multitasking, were also not available for older devices. Nevertheless, the latest iOS usually is adopted on more than 90 percent of devices within the first two months of their launch. The iOS 5 adoption rate wasn’t hindered, and the adoption rates were faster than those for iOS 4. This was probably because there weren’t any missing features for older phones (like iPhone 4). Also, older devices (like iPhone 3GS) didn’t run slower on iOS 5, unlike with iOS 4. Finally, cleaner notifications, iTunes, WiFi-sync, and iMessage were killer features that accelerated end users’ adoption ofiOS 5.

iOS 5.1 was the first over-the-air update, and adoption rates were even higher than for iOS 5. For iOS 6, I foresee similar high adoption rates. All this means that you want to start using every possible iOS 6 feature as soon as possible to get your app shining in all its glory. Features like collection views, and using Auto Layout to support the new taller iPhone 5 should be reason enough to update your apps to iOS 6. Having said that, it’s time to start your iOS 6 journey.

Further Reading

Apple Documentation

The following document is available in the iOS Developer Library at developer.apple.com or through the Xcode Documentation and API Reference.

What’s New in iOS 6

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.160.66