Introduction
In this article I will create a Single View application. Here I use an image view and one button from outlet in the first view. To implement the recorder we add an AVFoundation framework and add a second view from the resource. Finally we test this app in a device. It will successfully record sound and play it back on a device.
To understand how it works we use the following.
Step 1
Here first we add the framework AVFoundation which is required to implement the recorder class.
To import this framework we use the following.
Step 2
Click on the project and select Build Phase.
Step 3
Click on the "+" icon to add the framework.

Step 4
Now select the AVFoundation framework and click on the add button.

Step 5
Now we add an Objective-C Class of the UIView Controller type.
Step 6
Here we use one of the new concept of splash screen; for this we import an image to project and add it to the launch image. In the same way we add an app icon image.
Step 7
Now we write the code for each class.
AppDelegate.h
#import <UIKit/UIKit.h>
@class ViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;
@property (strong,nonatomic) UINavigationController *nav;
@end
AppDelegate.m
#import "AppDelegate.h"
#import "ViewController.h"
@implementation AppDelegate
- (void)dealloc
{
[_window release];
[_viewController release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
sleep(5);
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
self.nav = [[UINavigationController alloc] initWithRootViewController:_viewController];
self.window.rootViewController = self.nav;
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
exit(0);
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UINavigationControllerDelegate>
{
IBOutlet UIButton *recordbtn;
}
@property (strong,nonatomic)IBOutlet UIButton *recordbtn;
-(IBAction)click:(id)sender;
@end
ViewController.m
#import "ViewController.h"
#import "recorderview.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize recordbtn;
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Voice Recorder";
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
}
-(IBAction)click:(id)sender
{
recorderview *rec =[[recorderview alloc]init];
[UIView transitionWithView:self.navigationController.view duration:1
options:UIViewAnimationOptionTransitionCurlUp
animations:^{
[self.navigationController pushViewController:rec animated:NO];
}
completion:^(BOOL completed)
{
}
];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
ViewController.xib
recordview.h
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface recorderview : UIViewController <AVAudioRecorderDelegate,AVAudioPlayerDelegate>
{
IBOutlet UIButton *playbtn;
IBOutlet UIButton *stopbtn;
IBOutlet UIButton *recordbtn;
IBOutlet UIProgressView *progressview;
IBOutlet UIActivityIndicatorView *indicator;
BOOL toggle;
NSURL * recordedTmpFile;
NSTimer *timer;
AVAudioRecorder *audioRecorder;
AVAudioPlayer *audioPlayer;
}
@property (nonatomic,strong)IBOutlet UIActivityIndicatorView *indicator;
@property (nonatomic,strong)IBOutlet UIButton *playbtn;
@property (nonatomic,strong)IBOutlet UIButton *stopbtn;
@property (nonatomic,strong)IBOutlet UIProgressView *progressview;
@property (nonatomic,strong)IBOutlet UIButton *recordbtn;
@property (strong, nonatomic) AVAudioRecorder *audioRecorder;
@property (strong, nonatomic) AVAudioPlayer *audioPlayer;
- (IBAction) start_click;
- (IBAction) stop_click;
- (IBAction) Play_click;
@end
recordview.m
#import "recorderview.h"













Join the conversation! Your thoughts help the community grow.