Changes

Jump to: navigation, search

An Example iOS 4 iPhone Camera Application (Xcode 4)

229 bytes added, 20:01, 30 March 2011
no edit summary
The application user interface for this example will consist of an image view and two push buttons. When touched by the user, the first button will display the camera to the user and allow a photograph to be taken which will subsequently be displayed in the image view. The second button will provide access to the camera roll where the user may select an existing photo image. In the case of a new image taken with the camera, this will be saved to the camera roll.
Since we will be covering the playback of video in the next chapter ([[Video Playback from within an iOS 4 iPhone Application(Xcode 4)|Video Playback from within an iOS 4 iPhone Application]]) the camera roll and camera will be restricted to still images in this example. The addition of video support to this application is left as an exercise for the reader at the end of the next chapter.
== Creating the Camera Project ==
== Writing the Delegate Methods ==
As described in [[Accessing the iPhone Camera and Photo Library(Xcode 4)|Accessing the iPhone Camera and Photo Library]], in order to fully implement an instance of the image picker controller delegate protocol it is necessary to implement some delegate methods. The most important method is the didFinishPickingMediaWithInfo which is called when the user has finished taking or selecting an image. The code for this method in our example is as follows:
<pre>
== Building and Running the Application ==
In order to experience the full functionality of this application it will be necessary to install it on a physical iPhone or iPod Touch device with a camera. Steps on performing this are covered in [[Testing iOS 4 Apps on the iPhone – Developer Certificates and Provisioning Profiles(Xcode 4)|Testing iOS 4 Apps on the iPhone – Developer Certificates and Provisioning Profiles]].
Assuming certificates and provisioning are configured, click on the Run button to launch the application. Once application loads, select the Camera button to launch the camera interface:

Navigation menu