Home Mobile iOS 5 Essentials

iOS 5 Essentials

By Steven F. Daniel
books-svg-icon Book
eBook $25.99 $17.99
Print $43.99
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $25.99 $17.99
Print $43.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
About this book
Building on the phenomenal success of its predecessor iOS 5 includes over 200 new user features as well as an updated SDK containing over 1,500 new APIs. iOS 5 looks set to reinforce the iPhone's dominance in the smartphone market. iOS 5 Essentials will help you learn how to build simple, yet powerful iOS 5 applications incorporating iCloud Storage, Twitter, Core Image and Newsstand integration. You will start by learning about what's new in iOS 5. You'll look at the iCloud Storage APIs, Automatic Reference Counting, Twitter and AirPlay integration, how to use the various Core Image filters using the Cocoa framework, and the new features of the iOS 5 SDK. After this, you'll jump straight in and create applications using Xcode and Interface Builder using the new storyboard layout. We then finish up by learning how to make your applications run smoothly using the Xcode instruments.
Publication date:
January 2012
Publisher
Packt
Pages
252
ISBN
9781849692267

 

Chapter 1. What's New in iOS5

Welcome to the exciting world of iOS 5, the latest release of Apple's mobile operating system, which is packed with some great new features and improvements to the way things are done. The release of the iPhone 4, back in 2010, took the world by storm. Developers around the world have been embracing the new features, such as incorporating AirPlay features within their applications, making use of the retina display to provide crisp and high-definition graphics within their applications and games, as well as the accelerometer and gyroscope.

When Apple hosted their annual World Wide Developer Conference in June 2011, they introduced more than 200 new features, as well as an updated SDK that features over 1,500 new development APIs. This opened up a lot of ideas for many new applications and the way we do things currently, to be done differently. Some of the great new feature highlights are the ability to support the way in which notification messages are handled by using the new Notification Center , messaging has been greatly improved by using the new iMessage messaging application, and finally, the ability to organize and purchase all of your newspaper and magazine subscriptions using the new Newsstand application.

In this chapter, you will gain an insight into some of the fantastic new features and enhancements that have been incorporated into the latest iOS 5 release. We will also look at how to go about downloading and installing the Xcode developer tools and Software Development Kit (SDK).

In this chapter, we will:

  • Get introduced to some of the new features that come with iOS 5

  • Download and install the Xcode development tools

  • Create a simple application using the features of the Newsstand framework

  • Create a simple application that sends an e-mail, using the MessageUI framework

  • Remove the Xcode development tools

We have a exciting journey ahead of us, so let's get started.

 

What's new in iOS 5


Since the release of Apples iOS operating system back in June 2007, they have incorporated many new features and improvements within each release build of its operating system. In iOS 4, we saw this came with over 1,500 new APIs, as well as some high quality enhancements and improvements.

In iOS 5, Apple has introduced over 200 new features and improvements, as well as 1,500 new APIs and updates to its SDK, to include new features relating to Core Image, Twitter integration, and the Newsstand Kit.

Needless to say, the Xcode 4 development environment has also undergone some improvements to allow your applications to be compiled with the new LLVM compiler 3.0 that supports Automatic Reference Counting (ARC). Hence, you rarely need to retain or release your objects, as ARC does most of the work for you. In some cases, you will still need to use retain/release. Storyboard support has also been integrated into Interface Builder, which allows you to design multiple-view workflows for each of your views.

Lastly, debugging OpenGL ES projects are a lot easier, as these have been integrated into the Xcode debugging interface.

In the following sections, we will focus in detail on some of the new features that come with iOS 5.

Reminders

A neat new feature that comes as part of this release is the Reminders App. A good way to think of reminders would be to think of them as to-do lists. Reminders can prove to be a life-saver, as they give you the flexibility to organize your day-to-day tasks, and come complete with the ability to add due dates and locations.

When you set up your reminders to use locations, you can specify to be reminded on a specific day or location, as well as being reminded either when you arrive or leave the location. They make use of your mobile phone's GPS, similar to how your car's navigation system works, and are designed to alert you as soon as you approach the designated area. Let's take an example, say for instance, you wanted to buy a new printer and some additional ink, you set up your reminder to automatically send you an alert as soon as you pulled into your local stores, parking lot.

Finally, another thing to mention about reminders: since these have been integrated into iOS 5, they have been designed to work well with other applications. For example, Apple iCal, Microsoft Outlook, and iCloud. This has been done to ensure that any changes you make will automatically update on all of your devices and calendars.

The following screenshots shows a list of items that have been added to a to-do list, and then shows how you can configure and specify when to be reminded. You can choose to be reminded when you leave or arrive at a particular location. The final screenshot shows the reminder pop-up when the specified time has been reached. Additional items can be added to the list by selecting the + plus sign, as highlighted by a rectangle.

Notification Center

Notifications play an important role in an iPhone user's everyday life. Notifications come in the form of pop-ups to inform you that a new e-mail has arrived, of new SMS text messages, of friend requests from social networking sites, notifications when your phone credit falls below a certain amount, and much more. With the Notification Center application, you don't need to worry about locating that e-mail, SMS text message, or friend request. It has been made simple enough for you to keep track of all of these forms of notifications in one convenient location.

The Notification Center can be accessed by simply placing your finger anywhere at the top of the screen and swiping in a downward motion. There are many different notifications to choose from when you are in this view. For instance, you can choose to see the current weather forecast, your stock shares, calendar entries of upcoming appointments, and so on. As new notifications come through, they will be added and will appear at the top of the list for easier access, without interrupting what you're doing.

You can also act upon Notifications through the lock screen on your iOS device; these appear categorized within a table view, so that you can act on them quickly by simply sliding the panel to unlock and take you to the relevant application. For example, if you receive a message, this will open up the iMessage application. As you can see, the Notification Center provides you with a much better way of staying on top of your life's activities.

Newsstand

The Newsstand is a central place, where iOS users can access their subscribed magazines and newspapers. Unlike iBooks, where book publishers supply .epub files or similar documents, Newsstand publishers will have to create an iOS application (or adapt their existing application). Think of it like a cross between the shelf seen in the iBooks application and applications folders on the home screen.

To make use of the new features, publishers must invoke the newly added Newsstand Kit framework. There are some simple settings that need to be configured to allow your application to recognize that it is a magazine or a newspaper, so that it can be placed within the Newsstand application, instead of running as a standalone application.

In the coming section, we will proceed to download and install the iOS 5 SDK. If you have already installed this, you can skip this section altogether and proceed to the next section.

 

Getting and installing the iOS 5 SDK


Before we can start to build our iOS applications, you must first sign up as a registered iOS Developer at http://developer.apple.com/programs/ios/. The registration process is free and provides you with access to the iOS SDK and other developer resources that are really useful for getting you started.

Once you have signed up, you can then download the iOS SDK, as shown in the following screenshot. It may be worthwhile making sure that your machine satisfies the following system requirements prior to your downloading the iOS SDK:

  • Only Intel Macs are supported, so if you have another processor type (such as the older G4 or G5 Macs), you're out of luck

  • You have updated your system with the latest Mac OS X software updates for either OS X Lion or Snow Leopard

Note

If you want to develop applications for the iPad and iPod Touch, you can still use the iOS SDK, as they use the same operating system (OS) as the iPhone does. This SDK allows you to create universal applications that will work with both the iPhone and iPad running on iOS 4 and above.

Once you have downloaded the SDK, you can proceed with installing it. You will be required to accept a few licensing agreements. You will then be presented with a screen to specify the destination folder in which to install the SDK:

If you select the default settings during the installation phase, the various tools (explained in detail later) will be installed in the /Developer/Applications folder.

The installation process takes you through the custom installation option screens. You probably would have seen similar screens to this if you have installed other Mac software. The following screenshot shows what you will see here:

These options give you a little more control over the installation process. For example, you are able to specify the folder location to install Xcode, as well as settings for a variety of other options.

The iOS 5 SDK comes as part of the Xcode Developer Tools download, which you'll find at https://developer.apple.com/devcenter/ios/index.action.

The SDK consists of the following components:

  • Xcode: This is the main Integrated Development Environment (IDE) that enables you to manage, edit, and debug your projects

  • Dashcode: This enables you to develop web-based iOS applications and Dashboard widgets

  • iOS Simulator: This is a Cocoa-based application that provides a software simulator to simulate an iOS device on your Mac OS X

  • Instruments: These are the analysis tools that help you optimize your applications and monitor for memory leaks in real-time

The following screenshot displays a list of the various tools that are installed as part of the default settings, during the installation phase. These are installed in the /Developer/Applications folder:

In the next section, we will look at how we can use the power of the Newsstand Kit framework to enable developers to develop an application that will add items to our Newsstand, rather than this being launched as a separate iOS application.

 

Creating the MyMagazineArticle application


Before we can proceed with creating our MyMagazineArticle application, we must first launch the Xcode4.2 development environment. Double-click on the Xcode icon located in the /Developer/Applications folder.

Alternatively, you can use Spotlight to search for this: simply type Xcode into the search box and Xcode should be displayed in the list at the top. When Xcode is launched, you should see the Welcome to Xcode screen, as shown in the following screenshot.

It may be worth docking the Xcode icon to your Mac OS X launch bar for easy access, as we will be using it a lot throughout this book.

It is very simple to create the MyMagazineArticle application in Xcode. Just follow the steps listed here:

  1. Select Create a new Xcode project, then select iOS Application on the left.

  2. Select the Page-Based Application template from the Project template dialog-box.

  3. Then, click on the Next button to proceed to the next step in the wizard. This will allow you to enter in the Product Name and your Company Identifier.

    Note

    The company identifier for your App needs to be unique. Apple recommends that you use the reverse-domain style (for example, com.DomainName.AppName).

  4. Enter in MyMagazineArticle for the Product Name, and enter a unique identifier in the Company Identifier field, ensuring that you have selected iPhone from the Device Family drop-down box.

  5. Then, click on the Next button to proceed to the final step in the wizard.

  6. Choose the folder location where you would like to save your project.

  7. Then, click on the Create button to save your project at the location specified.

Once your project has been created, you will be presented with the Xcode development interface, along with the project files that the template created for you, within the Project Navigator window.

Adding the Newsstand Kit framework to our project

Now that we have created our project, we need to add the Newsstand Kit framework to our project. This is an important framework that provides us with the ability to make our application appear within the Newsstand application, provided in the latest iOS 5release.

To add this framework and any other frameworks to your project, select the Project Navigator Group, and then follow the simple steps outlined here:

  1. Select your project within the Project Navigator Window.

  2. Select your project target from under the TARGETS group.

  3. Select the Build Phases tab.

  4. Expand the Link Binary with Libraries disclosure triangle.

  5. Scroll down within the list and select the NewsstandKit.framework, and click on the Add button to add the item to our project. You can use the + button to add the library that you want to add; to remove a framework, highlight it from the group, and then click on the button. There is also the ability to search for the framework, if you can't find it in the list shown.

  6. If you are still confused on how to go about adding the NewsstandKit.framework, you can refer to the following screenshot, which highlights what parts you need to select (highlighted by a rectangle).

Adding properties to our application

Now that we have added the NewsstandKit.framework to our project, our next step is to start adding some properties to make our application show up within the Newsstand application.

Unlike other iOS applications, Newsstand applications that you create will only appear in the Newsstand application, and not displayed within the user's home screen like iOS applications currently do. Instead of displaying the application icon, the application will display a cover and some additional information provided by Newsstand. When a user taps the cover of your application, it will automatically launch your application and present them with information pertaining to that article.

Creating an application that uses the Newsstand Kit requires communication between your application and the servers that host your content. Your servers are responsible for notifying the application when any new updates or releases are available, typically using a push notification.

Note

For more information on push notifications, refer to the Apple Developer Connection documentation which can be found at the following address: http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction/Introduction.html.

In order to make our application act like a Newsstand application, and make it appear on the shelf, three steps are required. These are:

  1. Add the Newsstand Kit framework to your project.

  2. Include the UINewsstandApp key within your MyMagazineArticle-Info.plist file to indicate that it supports Newsstand. This can be achieved by clicking on the MyMagazineArticle-Info.plist file, then right-clicking within the center of the panel, and selecting Add Row from the pop-up list, as shown in the following screenshot:

  3. Include the Required background modes key with the newsstand-content value, for the application to be launched in the background so that it can start downloading the latest content. This can be achieved by clicking on the MyMagazineArticle-Info.plist file, and then right-clicking within the center of the panel and selecting Add Row from the pop-up list.

The following screenshot shows the options that are needed to be assigned to, make it appear within the Newsstand folder:

If your Newsstand application includes the required background modes key within the newsstand-content value, located within the MyMagazineArticle-Info.plist file, your newsstand application will be launched in the background, so that it can start downloading the latest version of your magazine or newspaper article.

The download process is self-managed, and is taken care of by the system, which then notifies your application when the content has been fully downloaded and made available.

In order to make our application appear within the newsstand folder, you will need to create an array entry CFBundleIconFiles under the CFBundlePrimaryIcons to include your standard application icon.

You then need to create your UINewsstandIcon with a CFBundle in there as well, as this is where you set your newspaper or magazine covers and specify the binding type, which gives your application an icon shape and its binding edge.

In the following screenshot, it shows how we can customize our application to have it show as a newspaper, by changing the UINewsstandBindingType property to UINewsstandBindingTypeNewspaper:

Once you have created these entries within your application's .plist file, by making sure that you have added the actual icon .png files to your project, you will be ready to compile, build, and run your application. The following screenshot will be displayed, which shows that our application has been successfully added as part of the Newsstand folder application, with its icon changed to display as a newspaper article.

When adding icons to your project, it is important to take note of the size. This is dependent whether or not you are developing this for an iPhone or iPad. In the following table, this lists the name, size, and platform that the icons pertain to.

Image name

Size (pixels)

iOS Platform

Icon.png

57x57

Universal application icon

Icon-72.png

72x72

iPad

Icon-64.png

64x64

iPad

Icon-32.png

32x32

iPad/iPhone

Icon-24.png

24x24

iPad/iPhone

Icon-16.png

16x16

iPad/iPhone

If we change the UINewsstandBindingType property back to UINewsstandBindingTypeMagazine, it will display our icon as a magazine cover.

Once you have modified this entry within your application's .plist file, you will be ready to compile, build, and run this application. The following screenshot will be displayed, which shows that our application has successfully been added as part of the Newsstand folder application, with its icon changed to display as a Magazine cover.

So there you have it. As you can see, by adding some simple properties to your applications .plist file, you can customize your application to either have its icon displayed as a magazine cover, or as a newspaper article.

Note

One important thing to mention is that Newsstand applications must include the UINewsstandApp key within your project's .plist file, to indicate that it supports the Newsstand feature. If this is not done, your application will appear as a normal application that will be displayed on the user's home screen.

 

Creating the MyEmailApp application


Sending an e-mail from within your application ensures that you don't need to re-launch your application after sending the e-mail. This can be a good thing, as it makes your application user-friendly, enabling the user to keep using your application without having to re-launch it.

In this section, we will be using the MessageUI framework to create a simple application that will allow in-app sending of e-mails, without the user having to exit your application and then re-launch it.

We will also look at how we can automatically fill the To, Subject, and Message Body fields, before finally seeing how we can access and customize the navigation bar color to suit your application. To see how we can achieve this, just follow these simple steps:

  1. Launch Xcode from the /Developer/Applications folder.

  2. Then, choose the Single View Application template from the project template dialog box:

  3. Click on the Next button to proceed to the next step within the wizard.

  4. Provide a name for your project by filling in the Product Name and Company Identifier fields.

  5. Enter in MyEmailApp for the Product Name.

  6. Ensure that iPhone is selected from the Device Family drop-down box.

  7. Click on Next, to proceed to the final step in the wizard.

  8. Choose the folder location where you would like to save your project.

  9. Then, click on the Create button to save your project at the location specified.

Adding the MessageUI framework to our project

Now that we have created our project, we need to add the MessageUI Framework to our project. This is an important framework that will provide us with the ability to send an e-mail message.

To add this framework, follow these simple steps:

  1. Select your project within the Project Navigator Window.

  2. Then, select your project target from under the TARGETS group.

  3. Select the Build Phases tab.

  4. Expand the Link Libraries with Libraries disclosure triangle.

  5. Then, scroll down within the list and select the MessageUI.framework, and click on the Add button to add the item to our project. You can use the + button to add the library that you want to add; to remove a framework, highlight it from the group, and then click on the button.

  6. If you are still confused as to how to go about adding the MessageUI.framework , you can refer to the following image, which highlights what parts you need to select (highlighted by a rectangle).

Building TheMyEmailApp user interface

In this section, we will start to build our user interface for the MyEmailApp. We will need to include the header file information for the MessageUI framework, which we added in the previous section.

This exposes all of the function methods and parameter calls. To see how this can be achieved, follow these simple steps:

  1. Now that we have added the required framework, our next step is to import the framework header file into our MyEmailAppViewController.h header file as follows:

    #import <MessageUI/MessageUI.h>
  2. Next, under the resources folder, open the MyEmailAppViewController.xib file, then drag a UIButton control from the Object Library, and set the buttons caption to display Send Email through its text property, or you can double-click on the button and type in the Send Email text.

    We need to create the method action event that will execute when this button has been pressed.

  3. In the MyEmailAppViewController.m implementation file, add the following code:

    - (IBAction)composeEmail{
      MFMailComposeViewController *controller =     [[MFMailComposeViewControlleralloc] init];
        [selfpresentModalViewController:controlleranimated:YES]; 
    
    controller.mailComposeDelegate = self [controller release];
    }

    This creates an MFMailComposeViewController object, and sets ourself up as the delegate, so that we can receive the callbacks.

  4. We need to dismiss our e-mail window view once we have sent our message. For this to happen, we need to implement a delegate handler to our mail compose view controller MFMailComposeViewControllerDelegate. This sets up your applications view-controller as the delegate, so that it can be notified when the user either sends or cancels the e-mail.

  5. Open the MyEmailAppViewController.h interface file, and then add the following code:

    #import <UIKit/UIKit.h>
    #import <MessageUI/MessageUI.h>
    
    @interface MyEmailAppViewController: UIViewController<MFMailComposeViewControllerDelegate> {} 
    @end
  6. We now need to implement a callback method, which will be used to dismiss the view controller when the user sends or cancels the e-mail.

  7. Open the MyEmailAppViewController.m implementation file, and add the following code:

    - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
      [selfdismissModalViewControllerAnimated:YES]; 
    }

Auto-populating fields

So far, we have added enough program logic to allow our application to function correctly, but this doesn't allow for certain fields to be auto-populated, so these will need to be manually filled in. To do this, we first need to add some additional code.

  1. Open the MyEmailAppViewController.m implementation file, and add the following code to the composeEmail method, as shown below:

    [controllersetSubject:@"Program Bug"]; 
    
    [controllersetToRecipients:[NSArrayarrayWithObject:[NSStringstringWithString:@"YourEmail@companyname.com"]]]; 
    [controllersetMessageBody:@"An application error has occurred within module XcodeFunctions.m" isHTML:NO];
    
    [controller.navigationBarsetTintColor:[UIColorredColor]];
    [selfpresentModalViewController:controlleranimated:YES]; 
    
    controller.mailComposeDelegate = self;
    [controller release];
  2. There is also the option to change the color of the navigation bar that is located at the top of the e-mail window. To achieve this, we need to use the setTintColor method of the navigationBar control. You will need to add this to the composeEmail method, just before the line that reads [self presentModalViewController:controller:

    [controller.navigationBarsetTintColor:[UIColorredColor]];
    [selfpresentModalViewController:controlleranimated:YES];
    

In this section, we have successfully added the code to pre-fill our e-mail composition sheet with default item details, and looked at how we can set the color of our navigation bar. In the next section, we will take a look at how to build and run our application.

 

Building and running the MyEmailApp application


Once you have implemented the previous code, it is time to compile, build, and run your application to see how it all works. The following screenshot below displays the MyEmailApp application running within the iOS simulator, with all of the fields populated:

So, there you have it. You have successfully built an application using the MessageUI framework that sends a new e-mail message. When you press the Send Email button, it displays the compose new e-mail view controller window directly within your application, with all fields pre-populated, and the navigation bar is colored appropriately. The action sheet that is shown in the last screenshot gets displayed when you press the Cancel button.

iMessage

iMessage is an integrated add-on to the existing Messages application that we have come to know and love. iMessage allows you to easily send text messages, photos, videos, or other content to an individual or a group of people on other iOS devices running iOS 5 over Wi-Fi or 3G.

These messages are also automatically pushed to all of your other iOS devices, thus making it easier to maintain one conversation across all devices. When sending messages using iMessage, your phone automatically checks to see if the phone number of the person that you are sending is running iOS 5, if this is the case, it will send them an iMessage message rather than a standard SMS text.

Up to this point, your address book will be updated and a small blue chat bubble will appear next to the name of the contact to indicate that they can receive iMessages. If the person is not running iOS 5, then the address book will be updated with a green chat bubble. In the following screenshot, it displays the iMessages feature, and displays the conversations in small blue bubbles to indicate that both people are running iOS 5:

The bullet points below summarize some of the advantages of using iMessage, as opposed to the standard messaging component.

  • iMessage brings the Message application for all iOS devices running iOS 5 – the iPhone, iPod touch, and iPad. Messages are pushed to all your devices, so if you start a conversion on your iPhone, you are able to continue and pick it upon any iOS device

  • iMessage service is built into the Message application, so users can send unlimited text, photos, videos, contacts, locations, and group messages for free, to their family and friends who have an iOS device. It is worth mentioning that, while this feature doesn't incur any text messaging fees, it does use your bandwidth allocation, and depending on how much you use, it might cost you more.

  • iMessage easily allows you to find out if someone is responding to your message in the form of an ellipsis, as seen on applications such as an instant messenger.

  • iMessage optionally allows you to track your messages with delivery receipt and read receipt.

  • You can send messages over Wi-Fi as well as over 3G.

  • Messages that are sent through iMessage are encrypted over the air.

iPhone Camera

Another component within the iPhone that has been updated in this latest release, is the iPhone Camera. Since the camera is the most widely used application to capture those special and unexpected moments, Apple has made this more accessible.

This application can now be accessed directly from your iPhone's lock screen, and features several improvements, such as:

  • Grid lines: These are very helpful for determining if the camera is leveled to ensure that you take a perfect shot every time, by using things in the horizon or edges of buildings.

  • Pinch-to-zoom gestures: This feature enables you to manually zoom in and out, directly, within the camera application, rather than using the slider at the bottom of the screen.

  • Single-tap focus: This feature allows you to lock the focus and the exposure to one area of the screen. Simply tap your finger anywhere on the screen.

  • Exposure locks to compose a picture on the fly: This feature allows you to lock the focus and the exposure of your image, by simply placing and holding your finger on the screen.

There have also been new photo editing improvements added to the Photos application, to enable you to manipulate your images, to either crop or rotate your image, or provide photo enhancements, such as removal of red-eye from your photos, all done directly within the Photos application

If you are using iCloud (we will be covering this in Chapter 2, Using iCloud and the Storage APIs), it is also possible to automatically load new photos onto your computer's desktop, should you prefer to edit them there using your preferred photo-editing tool.

PC Free

With the new PC Free feature that comes with iOS 5, users can set up and activate their devices without the need of a computer. Any new iOS software updates are deployed directly to your iOS devices, as well as any purchases made on your device from iTunes or the App Store. These are transferred securely over Wi-Fi using Secure Sockets Layer (SSL) back to your iTunes library.

Once you have properly set up and configured iCloud, your backups and restores will automatically be done for you, and stored within the Cloud, making it easier for you to deploy any iOS updates to each of your iOS devices or computers that use the same Apple ID.

The following screenshot displays options on how to set up your phone, restore your device from and iCloud backup, or from your iTunes library. Once this is done, you will receive a final Thank You screen, where you can start using your iOS device.

Wi-Fi sync

In iOS 5, Apple has provided an easier way for its users to wirelessly synchronize all of your iOS devices over a shared Wi-Fi connection directly back to your Mac or PC, without the need of having it connected directly to your computer, as you would have done previously.

What happens is that, each time you decide to charge your iOS device, it will automatically search for any new purchases or items that have been added to your device and then automatically synchronize this back to your iTunes library.

In this manner, you will always have a back up copy of all of your movies, precious home videos, and photo albums in one place, which can be accessed anytime you want them.

Multitasking gestures

Unfortunately, these never made it in the iOS 4 release; they were only included in the iOS 4 SDK for developers, but ended-up working really well on the iPad. In iOS 5, this has been greatly improved and includes a number of added features to make accessing content a lot easier. The engineers at Apple have made it simpler, and a lot easier to navigate around in as little moves as possible. They have also added shortcut menus to help you get around even quicker on the iPad.

These are achieved by using four or five fingers, and swiping upwards to reveal the multitasking bar and using the pinch motion to return to the Home screen. There has even been support added relating to swiping left or right, to switch between your applications.

Removing the Xcode developer tools

Should you ever wish to uninstall Xcode (in the event that something went wrong during installation, or you just want to uninstall the Xcode developer tools), it is a very straightforward process. Open an instance of the terminal window and run the uninstall-devtools script:

sudo <Xcode>/Library/uninstall-devtools --mode=all

<Xcode> is the directory where the tools are installed. For typical installations, the full path is /Developer/Library/uninstall-devtools.

<sudo> is a system admin command that will require you to enter in the administrator password before proceeding.

Note

Before you proceed, make sure this is what you really intend to do, as once it's gone, it's permanently deleted. In any event, you can always choose to reinstall the Xcode developer tools. It is worth checking that the /Developer/Library/Xcode/ folder has also been removed. If not, just move it to the trash.

 

Summary


In this chapter, we learned about the new features of iOS 5, and how to go about downloading and installing the iOS 5 SDK, as well as familiarizing ourselves with some of the Xcode development tools.

We then moved on, and looked at how to build a simple Newsstand application, using the Newsstand Kit framework, to show how we can add newspapers and magazines to the Newsstand application folder. Next, we looked at how we can use the MessageUI framework to build a simple e-mail application, and learned how we can customize the navigation bar UI to set the background color.

To end the chapter, we looked at the steps involved on how to uninstall the Xcode developer tools, using the command line.

In the next chapter, we will learn what iCloud exactly is that we keep hearing so much about it, and we will focus on the storage APIs that comes as part of iCloud. We will take a look at how to create an iCloud application to store documents and key-value data within the Cloud, how to perform a backup to the Cloud, and then finally look at how we can handle file-version conflicts.

About the Author
  • Steven F. Daniel

    Steven F. Daniel is the CEO and founder of GENIESOFT STUDIOS, a software development company based in Melbourne, Victoria, that focuses primarily on developing games and business applications for the iOS, Android, and Mac OS X platforms. He is an experienced software engineer with more than 17 years' experience and is extremely passionate about making people employable by helping them use their existing skills in iOS, Android, and Xamarin to get the job done. He is a member of the SQL Server Special Interest Group (SQLSIG), CocoaHeads, and the Java Community. He was the co-founder and Chief Technology Officer (CTO) at SoftMpire Pty Ltd., a company focused primarily on developing business applications for the iOS and Android platforms.

    Browse publications by this author
iOS 5 Essentials
Unlock this book and the full library FREE for 7 days
Start now