Cult Of Mac Monday Promo-Code Giveaways

The popular Apple fanboi site Cult Of Mac wants to trade you promotional codes for visibility. More specifically, they’re building a regular Monday promo code giveaway feature and are looking for app devs/publishers to volunteer some codes.

They’ve got a respectable 6,000 Twitter followers and around 2,400 Facebook fans. Zealots are valuable in word-of-mouth campaigns. I’d probably share codes with them vs. going it alone on Twitter/Facebook to get access to their audience.

Contact Leander Kahney, leander (AT) cultofmac (DOT) com, for details.

GDC: iPhone Developer’s Union Party Tomorrow (Weds) Night

GDC is on in San Francisco this week and, with it, comes the iPhone Developer’s Union party.

The party’s free to attend and open to all. Come mingle with our own Ari Braginsky, indie iPhone devs and the media who cover them.

Where/When: Marriott Lobby Bar (across from Moscone West). Weds, March 10 @ 8pm. No RSVPs, just show up.

Change View in iPad

In this application we will see how to change view in iPad.

Step 1: Create a Window base application using template. Give the application name “Windowbase_iPad”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: xpand classes and notice Interface Builder created the Windowbase_iPadAppDelegate class for you. Expand Resources and notice the template generated a separate nib, MainWindow.xib, for the “Windowbase_iPad”.

Step 4: We need to add two images in the resource folder. Give the name of the resources “1-1.png”,”2-1.png”.

Step 5: We have added QuartzCore.framework, select Frameworks -> add -> Existing frameworks -> selectQuartzCore.framework.

Step 6: In the Windowbase_iPadAppDelegate.h file, we have added instances of UIView and UIImageView class, and create one IBAction method. So make the following changes in the file.

#import <UIKit/UIKit.h>

@interface Windowbase_iPadAppDelegate : NSObject <UIApplicationDelegate> {
   
        UIWindow *window;
        UIView  *subView;
        UIImageView *view1;
        UIImageView *view2;
        BOOL change;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UIView  *subView;

(IBAction)ChangeView:(id)sender;

Step 7: Double click your MainWindow.xib file open it to the Interface Builder. Open the the window and drag view from the library and place it to the window. Next drag Toolbar from the library and place it buttom of the view window. Now select ViewChangeAppDelegate, and bring up connection inspector. Select from subView to the view, and ChangeView to the BarButtonItem. Now save your .xib file and go back to the Xcode.

Step 8: Open the Windowbase_iPadAppDelegate.m file and make the following changes in the file.

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
       
        UIImage *image1 = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"1-1.png" ofType:nil]];
        view1 = [[UIImageView alloc] initWithImage:image1];
        UIImage *image2 = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"2-1.png" ofType:nil]];
        view2 = [[UIImageView alloc] initWithImage:image2];
        view2.hidden = YES;
        [subView addSubview:view1];
        [subView addSubview:view2];
        change = NO;
       
        [window makeKeyAndVisible];
       
        return YES;
}

(void)performTransition
{
       
        CATransition *transition = [CATransition animation];

        transition.duration = 0.75;
        transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
       
        NSString *types[4] = {kCATransitionMoveIn, kCATransitionPush, kCATransitionReveal, kCATransitionFade};
        NSString *subtypes[4] = {kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom};
        int rnd = random() % 4;
        transition.type = types[rnd];
        if(rnd < 3)     {
                transition.subtype = subtypes[random() % 4];
        }
       
        change = YES;
        transition.delegate = self;
       
        [subView.layer addAnimation:transition forKey:nil];
       
        view1.hidden = YES;
        view2.hidden = NO;
       
        UIImageView *tmp = view2;
        view2 = view1;
        view1 = tmp;
}

(void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
{
        change = NO;
}

(IBAction)ChangeView:(id)sender
{
        if(!change)
        {
                [self performTransition];
        }
}

Step 9: Now compile and run the application in the Simulator.

You can Download SourceCode from here Windowbase_iPad

Make $400 to $5000 DAILY from Ad Revenues With Your Free App

The iPhone Apps get-rich-quick landscape is best suited for one of two people development shops. However, some companies are also making good revenues – specifically from in-app advertising.

In the report below, AdWhirl says that top apps can make $400 to $5,000 per day on ads. The average CPM works out to around $2 per 1000 impressions. It may not look  impressive but its substantially better than the CPM rates at Facebook or MySpace apps.

However – These apps are from the most popular section on the app store… listing within the top 100 free apps. This is what is causing a problem for small developers. You need to crack into the top 100 if you want to get to the $400 daily revenue target.



Adwhirl iPhone Advertising Snapshot



You can access the Adwhirl data report directly here.

Display Splash Screen in iPad

In this application we will see how to display Splash Screen in iPad.

Step 1: Create a View base application using template. Give the application name “DisplaySplash_iPad”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: Expand classes and notice Interface Builder created the DisplaySplash_iPadViewController class for you. Expand Resources and notice the template generated a separate nib, DisplaySplash_iPadViewController.xib, for the “DisplaySplash_iPad”.

Step 4: We need to add one resource in the resource folder for display splash.

Step 5: In the DisplaySplash_iPad.h file, we have created instance of UIView class and two methods. So make the following changes in the file.

#import <UIKit/UIKit.h>

@interface DisplaySplash_iPadViewController : UIViewController {

        IBOutlet UIView *displaySplashScreen;
       
}

(void)displayScreen;
(void)removeScreen;

Step 6: Double click the DisplaySplash_iPadViewController.xib file and open it to the Interface Builder. Drag the view from the library and place it to the Main Window. Open the second view icon from the MainWindow,drag the image view from the library and place it to the view window,select the view and bring up Attribute Inspector select the image “themes.png”. Select the File’s Owner icon from the MainWindow and bring up Connection Inspector, drag from the displayScreen to the last view icon and connect File’s Owner icon to the view. Now save it , close it and go back to the Xcode.

Step 7: Open the DisplaySplash_iPad.m file and make the following changes in the file.

(void)displayScreen
{
       
        UIViewController *displayViewController=[[UIViewController alloc] init];
        displayViewController.view = displaySplashScreen;
        [self presentModalViewController:displayViewController animated:NO];
    [self performSelector:@selector(removeScreen) withObject:nil afterDelay:6.0];
       
       
}

(void)removeScreen
{
        [[self modalViewController] dismissModalViewControllerAnimated:YES];
}

Step 8 : Now compile and run the application in the Simulator.

You can Download SourceCode from here DisplaySplash_iPad

Mail Send from iPad

This is the very simple application. In this application we will see how to mail send from the iPad.

Step 1: Create a View base application using template. Give the application name “MailComposer”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: Expand classes and notice Interface Builder created the MailComposerViewController class for you. Expand Resources and notice the template generated a separate nib, MailComposerViewController.xib, for the “MailComposer”.

Step 4: We need to add MessageUI Framework. Select Frameworks folder ->Add -> Existing Framework -> Add MessageUI Framework.

Step 5: In the MailComposerViewController.h file , we have import MessageUI framework. Create an instance of UIButton class and add one buttonPressed method. So make the following changes in the file.

#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>

@interface MailComposerViewController : UIViewController
<MFMailComposeViewControllerDelegate>
{
        IBOutlet UIButton *button;
}

(IBAction)buttonPressed;

Step 6: Double click MailComposerViewController.xib file and open it to the Interface Builder. First drag the Round Rect button from the library and place it to the view window. Connect File’s Owner icon to the View icon and select view. Drag File’s Owner icon to the round Rect button and select button and select the Round Rect button and bring up Connection Inspector next drag Touch Up Inside to the File’s Owner icon and select buttonPressed: action. Now save the MailComposerViewController.xib file, close it and go back to the Xcode.

Step 7: Open the MailComposerViewController.m file and make the following changes in the file.

(void)viewDidLoad {
        if ([MFMailComposeViewController canSendMail])
                button.enabled = YES;
}

(IBAction)buttonPressed {
        MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
        mailController.mailComposeDelegate = self;
        [mailController setSubject:@"Hello World"];
        [mailController setMessageBody:@"This is the MailSend Application…." isHTML:NO];
        [self presentModalViewController:mailController animated:YES];
        [mailController release];
}

(void)mailComposeController:(MFMailComposeViewController*)mailController didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
        [self becomeFirstResponder];
        [self dismissModalViewControllerAnimated:YES];
}

Step 8: Now Compile and run the application in the Simulator.

You can Download SourceCode from here MailComposer

CNBC Feature – Planet of the Apps

Planet of the Apps: A Hand-held Revolution Premiered on January 7th 10pm ET on CNBC. In this program CNBC looked at at how apps have changed our lives, and they meet some of the creators behind them, and figure out just how big a business they really are. For those who missed the CNBC special feature on iPhone Apps, this is 45 minute show is a must see / download. Just search on Youtube for related clippings or if you know where on torrents you can probably download the full episode from – if in USA from Hulu, picrap.com, clicker.com or any TV show streaming site. For more information. Please log onto: www.planetoftheapps.cnbc.com

Click here to view the embedded video.

Music Play in iPhoneOS4

This is the very simple example . In this application we will see how to play music in iPhone oS4.

Step 1: Create a new project in Xcode using View base application. Give the application name “MusicPlay_OS4”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: xpand classes and notice Interface Builder created the MusicPlay_OS4ViewController class for you. Expand Resources and notice the template generated a separate nib, MusicPlay_OS4ViewController.xib, for the “MusicPlay_OS4”.

Step 4: We need to add sound files in the Resources folder. Give the name of the sound files “music.mp3”,”sound.aif”. And also add a backgroung image.

Step 5: We need to add also two frameworks.So select Frameworks -> Add -> Existing Framework -> then select AVFoundation.framework and AudioToolbox.framework.

Step 6: In the MusicPlay_OS4ViewController.h file, we have  importAVFoundation.framework and AudioToolbox.framework. Create a instance of  AVAudioPlayer and UIButton class and create two IBAction method. So make the following changes in the file.

#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h>

@interface MusicPlay_OS4ViewController : UIViewController
<AVAudioPlayerDelegate>{
       
        SystemSoundID systemSoundID;
        AVAudioPlayer *player;
        UIButton *StartStopSound;
       
}

@property (nonatomic, retain) IBOutlet AVAudioPlayer *player;
@property (nonatomic, retain) IBOutlet UIButton *StartStopSound;

(IBAction) playSound: (id) sender;
(IBAction) playSong: (id) sender;

Step 7: Double click the MusicPlay_OS4ViewController.xib file and open it to the Interface Builder. First drag the Image View from the library and place it to the View window. Select the image view and bring up Attribute Inspector, select the background image. Drag two Round Rect button from the library and place it to the view window.Give the name of the button “Play Sound “and “Play Song” Connect File’s Owner icon to the View icon and select View. Drag File’s Owner icon to the Play Song button and select StartStopSound. Select the Play Sound button and bring up Connection Inspector and drag from the Touch Up Inside to the File’s Owner icon, select playSound: action. Do the same thing with PlaySong button and select the playSong: action. Now save the MusicPlay_OS4ViewController.xib file, close it and go back to the Xcode.

Step 8: Open the MusicPlay_OS4ViewController.m file and make the following changes in the file.

(void)viewDidLoad {
        NSLog(@"InView did load");
        AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle]
                                                                                                                                           pathForResource: @"sound" ofType:@"aif"]],
                                                                         &systemSoundID);
   
       
        player = [[AVAudioPlayer alloc]
                          initWithContentsOfURL:[NSURL fileURLWithPath:
                                                                         [[NSBundle mainBundle] pathForResource:@"music" ofType:@"mp3"]]
                          error:nil];
       
       
        [player prepareToPlay];
       
       
       
}

(IBAction) playSound:(id) sender {
       
        NSLog(@"In Sample");
        AudioServicesPlaySystemSound(systemSoundID);
}

(IBAction) playSong:(id) sender {
       
        if ([[NSString stringWithFormat:@"%@", [StartStopSound titleForState:UIControlStateNormal]] isEqualToString:@"Play Song"]) {   
                [player play]
                [StartStopSound setTitle:@"Stop Song" forState:UIControlStateNormal];   }
        else { 
                [player stop]
                [StartStopSound setTitle:@"Play Song" forState:UIControlStateNormal];  
        }      
}

Step 9: Now compile and run the application in the Simulator.

You can Download Source Code from here MusicPlay_OS4

Distimo Mobile Report – July 2010

This report covers the Apple App Store for iPad and iPhone (with specific focus on in-app purchases), as well as BlackBerry App World (Worldwide), Google Android Market, Nokia Ovi Store, Palm App Catalog and Windows Marketplace for Mobile for June 2010 in the United States. The major findings are:

* The percentage of applications with in-app purchases is significantly higher in the Apple App Store for iPad (10%) than in the Apple App Store for iPhone (2%). The Games and Social Networking categories in both stores have the highest proportion of applications with in-app purchases available.

* The most successful free applications that monetized using in-app purchases this month in the Apple App Store for iPhone are MobiTV (MobiTV), ESPN 2010 FIFA World Cup (ESPN) and Tap Fish (BayView Labs).

* The most successful paid applications that monetized using in-app purchases this month in the Apple App Store for iPhone are Guitar Hero (Activision Publishing, Inc.), TomTom U.S.A. (TomTom International BV) and Call of Duty: World at War: Zombies II (Activision Publishing, Inc.).

* Mirroring the Distimo report covering May 2010, Pages and iBooks, published by Apple Inc, are again the number one paid and free applications on the Apple App Store for iPad, respectively.

* Three out of the ten most popular applications in the Apple App Store for iPhone were published by Electronic Arts.

* Quickoffice Connect Mobile Suite for iPad entered the top 10 highest ranked paid applications chart in the 6th position. It was the top grossing application in the Apple App Store for iPad after Pages by Apple Inc.

* Nine out of the ten most popular paid applications on the Apple App Store for iPhone are Games, however only two out of the ten most popular free applications are Games. In the Nokia Ovi Store, seven out of ten of the most popular paid applications are Games, while only three out of ten of the most popular free applications are Games.

You can download the report here.

ViewBase application in iPad

This is the simple View Base application. In this application we will display image,  button and label.

Step 1: Create a View base application using template. Give the application name “ViewBase_iPad”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: Xpand classes and notice Interface Builder created the ViewBase_iPadViewController class for you. Expand Resources and notice the template generated a separate nib,ViewBase_iPadViewController.xib, for the “ViewBase_iPad”.

Step 4: In the ViewBase_iPadViewController.h file, we have created instance of UILabel and UIImage class. Define one IBAction method. So make the following changes.

#import <UIKit/UIKit.h>

@interface ViewBase_iPadViewController : UIViewController {
       
 IBOutlet UILabel *myLabel;
 IBOutlet UIImage *myImage;

}

@property(nonatomic,retain) IBOutlet UILabel *myLabel;
@property(nonatomic,retain) IBOutlet UIImage *myImage;

(IBAction)ButtonPressed:(id)sender;

Step 5: Double click the ViewBase_iPadViewController.xib file and open it to the Interface Builder.First drag the Image View from the library and place it to the View window. Next drag label and Round Rect from the library and place it to the view window. Select the Round Rect from the view window and bring up Connection iNspector. Drag from the Touch Up Inside to the File’s Owner icon and select ButtonPressed: method. Connect File’s Owner icon to the View icon and select view and connect File’s Owner icon to the label select myLabel. Now save the ViewBase_iPadViewController.xib file, close it and go back to the Xcode.

Step 6: Open the ViewBase_iPadViewController.m file and make the following changes in the file.

(IBAction)ButtonPressed:(id)sender{

myLabel.text = @"Welocome to the Real World!!!";
}

Step 7: Now compile and run the application in the Simulator.

You can Download SourceCode from here ViewBase_iPad

Download Apple WWDC 2010 Session Videos and Source Code

This might be a bit late, but just in case you missed this one and did not get the email from Apple – please do have a look! You don’t need to purchase the DVDs if you missed this years Apple WWDC session. To access them, all you need is a registered Apple developer account from – http://developer.apple.com/videos/wwdc/2010/. Grab them in both low and high definition, and if you don’t have an account ask your friendly neighbor or get on Youtube or some other video sharing sites to see what is uploaded there :)

Here is the link – Must Watch WWDC 2010 Keynotes!

Mobile Report by Distimo, June 2010 – A Must Read for Business Intelligence Data

This report covers the Apple App Store for iPad, the Apple App Store for iPhone, BlackBerry App World (Worldwide), Google Android Market, Nokia Ovi Store, Palm App Catalog and Windows Marketplace for Mobile for May 2010 in the United States.

The major findings are:

More than 50% of applications are priced below or equal to $2.00 in all stores, with the exception of BlackBerry App World and Windows Marketplace for Mobile.

The average price of all paid applications and the 100 most popular paid applications in the Apple App Store for iPad ($4.65) is higher than in the Apple App Store for iPhone ($4.01). However, the average price of the 100 top grossing applications is higher on the Apple App Store for iPhone.

Google Android Market has the largest share of free applications (57%) and Windows Marketplace for Mobile has the smallest (22%).

Twitter, Inc. published their native application in the Apple App Store and Google Android Market, becoming the monthly number 10 free application in the Apple App Store for iPhone, and the number 6 free application in Google Android Market.

Nine out of the ten most popular free applications and eight out of ten most popular paid applications in the Apple App Store for iPhone are games.

In the competitive e-reader market, both the iBooks application by Apple, Inc., and the Kindle application by Amazon.com are ranked among the 10 most popular free applications in the Apple App Store for iPad. Apple’s application is ranked number one however, and Amazon’s application is ranked number ten.

Five out of the ten most popular free applications in Windows Marketplace for Mobile are published by Microsoft Corporation.

You may download the entire report for free here!

Display WebPage and AudioFile play in TabBar Application

This is the TabBar application. In this application we will see how to display Web page and play audio file in the iPad. We will create this application using TabBar Application Template.

Step 1: Create a TabBar application using template. Give the application name “Tabbar_Videoplay_iPad”.

Step 2: code automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: Xpand classes and notice Interface Builder created the TabBarApplication_iPadViewController class for you. Expand Resources and notice the template generated a separate nib,TabBarApplication_iPadViewController.xib, for the “TabBarApplication_iPad”.

Step 4: We need to add UIViewController class in the project . Select classes -> Add -> New Files -> Select UIViewController class and give the class name “AudioPlayViewController”. Select corresponding .xib file and targeted for iPad.

Step 5: We have added AudioToolbox and AVFoundation framework in the Frameworks folder.

Step 6: We need to add two music file in the resource folder. Give the name of the music file “sound.aif”,”music.mp3″.

Step 7: In the FirstViewController.h file we have created instance of UIWebView class . So make the following changes in the file.

#import <UIKit/UIKit.h>

@interface FirstViewController : UIViewController {
  IBOutlet UIWebView *webDisplay;
}
@property(nonatomic,retain) UIWebView *webDisplay;

Step 8: Double click the MainWindow.xib file and open it to the Interface Builder. Select the FirstViewController from the TabBar Controller and bring up Attribute Inspector and delete the NIB name . Now drag the WebView from the library and place it to the view window. Select the first tab from the view window and bring up Connection Inspector and connect webDisplay to the Web View. Save the MainWindow.xib file and close it and go back to the Xcode.

Step 9: Open the FirstViewController.m file and make the following changes in the file.

(void)viewDidLoad {
       
        NSString *urlAddress = @"http://www.google.com";
        NSURL *url = [NSURL URLWithString:urlAddress];
        NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
        [webDisplay loadRequest:requestObj];
       
    [super viewDidLoad];
}

Step 10: In the AudioViewController.h file , we have import AudioToolbox and AVFoundation framework. Create an instance of  AVAudioPlayer and UIButton class. Define two IBAction method. So make the following changes in the file.

#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h>

@interface AudioPlayViewController : UIViewController  <AVAudioPlayerDelegate> {

        SystemSoundID systemSoundID;
        AVAudioPlayer *player;
        UIButton *StartStopSound;
       
}

@property (nonatomic, retain) IBOutlet AVAudioPlayer *player;
@property (nonatomic, retain) IBOutlet UIButton *StartStopSound;

(IBAction) playSound: (id) sender;
(IBAction) playSong: (id) sender;

Step 11: Double click the AudioPlayViewController.xib file and open it to the view window. First drag the two Round Rect from the library and place it to the view window and give the name “Play Sound” , “Play Song”. Select the  ”Play Sound” button and bring up connection Inspector and drag Touch Up Inside to the File Owner icon select playSound: action. Do the same thing for the “Play Song”  button and select the playSong: action. Connect File’s Owner icon to the “Play Song” button and select StartStopSound. Now save the AudioPlayViewController.xib file, close it and go back to the Xcode.

Step 12: Open the AudioPlayViewController.m file and make the following changes:

(void)viewDidLoad {
        NSLog(@"InView did load");
        AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle]
                                                                                                                                           pathForResource: @"sound" ofType:@"aif"]],
                                                                         &systemSoundID);
   
       
        player = [[AVAudioPlayer alloc]
                          initWithContentsOfURL:[NSURL fileURLWithPath:
                                                                         [[NSBundle mainBundle] pathForResource:@"music" ofType:@"mp3"]]
                          error:nil];
       
       
        [player prepareToPlay];
       
       
       
}

(IBAction) playSound:(id) sender {
       
        NSLog(@"In Sample");
        AudioServicesPlaySystemSound(systemSoundID);
}

(IBAction) playSong:(id) sender {
       
        if ([[NSString stringWithFormat:@"%@", [StartStopSound titleForState:UIControlStateNormal]] isEqualToString:@"Play Song"]) {   
                [player play]
                [StartStopSound setTitle:@"Stop Song" forState:UIControlStateNormal];   }
        else { 
                [player stop]
                [StartStopSound setTitle:@"Play Song" forState:UIControlStateNormal];  
        }      
}

Step 13: Double click the MainWindow.xib file and open it to the Interface Builder. Select the ViewController from the TabBar Controller  in MainWindow and bring up Identity Inspector and change the class name into AudioPlayViewController and bring up Attribute Inspector, set the NIB name into “AudioPlayViewController”. Now save the MainWindow.xib file, close it and go back to the Xcode.

Step 14: Now Compile the application and run it in the Simulator.

You can Download SourceCode from here Tabbar_Videoplay_iPad

Hello World with Navigation Base application in iPhone

This is the very simple example. In this example we will see how to Hello iPhone display using navigation base application.

Step 1: Create a Navigation Base application using template. Give the application name “HelloWorld_NavigationBase”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: Xpand classes and notice Interface Builder created the RootViewController class for you (See the figure below). Expand Resources and notice the template generated a separate nib,RootViewController.xib, for the “HelloWorld_NavigationBase”.

Step 4: Open the RootViewController.m file, for this example we need to add only two lines of code in this file . So make the changes.

(void)viewDidLoad {
    [super viewDidLoad];

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
     self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

  (UITableViewCell *)tableView:(UITableView *)tableView   cellForRowAtIndexPath:(NSIndexPath *)indexPath {

   static NSString *CellIdentifier = @"Cell";

   UITableViewCell *cell = [tableView  dequeueReusableCellWithIdentifier:CellIdentifier];
  if (cell == nil) {
   cell = [[[UITableViewCell alloc]   initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]    autorelease];
}

  // Configure the cell. // added below two line
    [[cell textLabel] setTextAlignment:UITextAlignmentCenter];
    [cell.textLabel setText:@"Hello iPhone!"];

   return cell;
}

Step 5: Now compile and run the application in the Simulator.

You can Download SourceCode from here HelloWorld_NavigationBase

MapKit example in iPhone

In this application we will see how to map display and how to point out any location using latitude and longitude.

Step 1: Create a View base application using template. Give the application name “MapKitDisplay”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: Xpand classes and notice Interface Builder created the MapKitDisplayViewController class for you. Expand Resources and notice the template generated a separate nib, MapKitDisplay ViewController.xib, for the “ MapKitDisplay”.

Step 4: We need to add NSObject class in the project. Select Classes -> Add -> New File -> Cocoa Touch Class -> Objective C class -> select NSObject from the Subclass of. Give the file name “DisplayMap”.

Step 5: We have added two framework in the project. Select Frameworks -> Add -> Existing Frameworks -> Add CoreLocation.framework and MapKit.framework.

Step 6: In the MapKitDisplayViewController.h file, we have import MapKit framework, and define MKMapViewDelegate protocol in the file, also add Outlet with a pointer to the MkMapView class. So make the following changes in the file.

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>

@class DisplayMap;

@interface MapKitDisplayViewController : UIViewController <MKMapViewDelegate> {
       
        IBOutlet MKMapView *mapView;
}
@property (nonatomic, retain) IBOutlet MKMapView *mapView;

Step 7: Double click the MapKitDisplayViewController.xib file and open it to the Interface Builder. First drag the MapView from the library and place it to the view window. Connect File’s Owner icon to the View icon and select view. Connect File’s Owner icon to the MKMapView and select mapView. Now save the MapKitDisplayViewController.xib file, close it and go back to the Xcode.

Step 8: Open the MapKitDisplayViewController.m file and make the following changes in the file:

(void)viewDidLoad {
    [super viewDidLoad];
       
        [mapView setMapType:MKMapTypeStandard];
        [mapView setZoomEnabled:YES];
        [mapView setScrollEnabled:YES];
        MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
        region.center.latitude = 22.569722 ;
        region.center.longitude = 88.369722;
        region.span.longitudeDelta = 0.01f;
        region.span.latitudeDelta = 0.01f;
        [mapView setRegion:region animated:YES];
       
        [mapView setDelegate:self];
       
        DisplayMap *ann = [[DisplayMap alloc] init];
        ann.title = @" Kolkata";
        ann.subtitle = @"Mahatma Gandhi Road";
        ann.coordinate = region.center;
        [mapView addAnnotation:ann];
}

(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
 (id <MKAnnotation>)annotation {
        MKPinAnnotationView *pinView = nil;
        if(annotation != mapView.userLocation)
        {
                static NSString *defaultPinID = @"com.invasivecode.pin";
                pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
                if ( pinView == nil ) pinView = [[[MKPinAnnotationView alloc]
                                                                                  initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];

                pinView.pinColor = MKPinAnnotationColorRed;
                pinView.canShowCallout = YES;
                pinView.animatesDrop = YES;
                }
        else {
                [mapView.userLocation setTitle:@"I am here"];
        }
        return pinView;
}

We define here first, coordinate regions to zeros, Then we enter coordinates of our place that, Kolkata (Mahatma Gandhi Road), define the latitude and longitude of this place. We create an instantiate of DisplayView object and add it to our map. To do this, we add the delegate function that will display the annotations on to our map. We start by having DisplayView name a pointer we’ll call “ann.”

Step 8: In the DisplayView.h file , we have import and set CLLocation class reference to incorporate the geographical coordinates and altitude of our device. So make the following changes in the file.

#import <Foundation/Foundation.h>
#import <MapKit/MKAnnotation.h>

@interface DisplayMap : NSObject <MKAnnotation> {

        CLLocationCoordinate2D coordinate;
        NSString *title;
        NSString *subtitle;
}
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;

Step 9: Open the DisplayView.m file and make the following changes in the file:

#import "DisplayMap.h"

@implementation DisplayMap

@synthesize coordinate,title,subtitle;

(void)dealloc{
        [title release];
        [super dealloc];
}

Step 10: Now compile and run the application on the simulator.

You can Download SourceCode from here MapKitDisplay