IT tutorials
 
Mobile
 

Iphone Application : Using Address Book, Email, and Maps (part 1)

12/9/2012 11:32:10 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
In this article, we will allow users to pick a contact as their best friend from their address book. After they have picked their best friend, we will retrieve information from the address book about their friend and display it nicely on the screen—including their name, photo, and email address. We will also give the user the ability to show their friend’s home city in an interactive map and send them an email—all within a single app screen.

Implementation Overview

This project covers quite a bit of area, but you don’t have to enter an extensive amount of code. We’ll start by creating the interface, and then add address book, map, and, finally, email features. Each of these will require frameworks to be added and modifications to the #import lines in our view controller’s interface file. In other words, if something doesn’t seem to be working, make sure you didn’t skip any steps on adding the frameworks!

Setting Up the Project

Start Xcode and create a new View-based iPhone application called BestFriend, then open the BestFriendViewController.h interface file and add two outlets for UILabels named name and email, an outlet for a UIImageView named photo, an outlet for a MKMapView object named map, and an instance variable of the type MKPlacemark, called zipAnnotation.

The application will also implement two actions: newBFF, which will be called to enable the user to choose a new friend from the address book; and sendEmail to send an email to your buddy.

Add these to your interface file, including the appropriate @property directives for each of the outlet variables. Your interface file should now resemble Listing 1.

Listing 1.
#import <UIKit/UIKit.h>

@interface BestFriendViewController : UIViewController {
    IBOutlet UILabel *name;
    IBOutlet UILabel *email;
    IBOutlet UIImageView *photo;
    IBOutlet MKMapView *map;
    MKPlacemark *zipAnnotation;
}

@property (nonatomic, retain) UILabel *name;
@property (nonatomic, retain) UILabel *email;
@property (nonatomic, retain) UIImageView *photo;
@property (nonatomic, retain) MKMapView *map;

- (IBAction)newBFF:(id)sender;
- (IBAction)sendEmail:(id)sender;

@end

Next, add the corresponding @synthesize lines to the BestFriendViewController.m file following the @implementation line:

@synthesize name;
@synthesize photo;
@synthesize email;
@synthesize map;

Finally, release these in the dealloc method:

- (void)dealloc {
    [name release];
    [email release];
    [photo release];
    [map release];
    [super dealloc];
}

By the Way

If you’re questioning why zipAnnotation isn’t added as a property, it’s because we only need to access the instance variable throughout the BestFriendViewController class. It wouldn’t hurt to define it as such, but we won’t be manipulating it as we do with the other interface elements.


Next, let’s open the BestFriendViewController.xib interface file and build the application UI.

Creating the Application’s UI

With all the appropriate outlets and actions in place, we can quickly build the application’s user interface. Instead of trying to describe where everything goes, take a look at Figure 1 to see my approach.

Figure 1. Create the application interface to resemble this, or use your own design!


Follow these steps to build the application’s UI:

1.
Add two labels (UILabel) one (larger) for your friend’s name, the other for his or her email address. In my UI, I’ve chosen to clear the contents of the email label.

2.
Add a UIImageView that will hold your buddy’s photograph from the Address Book. Use the Attributes Inspector to change the image scaling to Aspect Fit.

3.
Drag a new instance of MKMapView into the interface. This is the map view that will ultimately display your location and the city your buddy is in.

4.
Finally, add two buttons (UIButton)—one to choose a buddy and another to email your buddy.

Configuring the Map View

After adding the map view, select it and open the Attributes Inspector. Use the Type drop-down menu to pick which type of map to display (satellite, hybrid, and so on), and then activate all the interaction options. This will make the map show the user’s current location and enable the user to pan and zoom within the map view (just like in the map application!).

Connecting the Outlets and Actions

You’ve done this a thousand times (okay, maybe a few dozen), so this should be pretty familiar. Within Interface Builder, Control-drag from the File’s Owner icon to the labels, image view, and map view choosing name, email, photo, and map as necessary.

Next, use the Connection Inspector for the two buttons to connect the Touch Up Inside events to the newBFF and sendEmail actions.

Finally, use the Connection Inspector on the map view to connect its delegate outlet to the File’s Owner icon. This will tell the map that, when it’s time to display an annotation, it should be looking to the BestFriendViewController class to find the mapView:viewForAnnotation method.

With those connections, you’re done with the interface! Even though we will be presenting an email and address book interface—these elements are going to be generated entirely in code.

 
Others
 
- Iphone Application : Extending Application Integration
- Introducing Windows Phone 8 : Phone Specifications
- Introducing Windows Phone 8 : A Different Kind of Phone
- iPhone Application Development : Working with Rich Media - Accessing and Playing the iPod Library
- Android Application Development : Initialization in MicroJobs.java (part 2)
- Android Application Development : Initialization in MicroJobs.java (part 1)
- Android Application Development : Initialization Parameters in AndroidManifest.xml
- Iphone Application : Working with Rich Media - Using the Photo Library and Camera
- Iphone Application : Creating and Playing Audio Recordings
- Windows Phone 7 : AppHub and the Windows Marketplace for Mobile (part 2)
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us