This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Showing posts with label Ipad. Show all posts
Showing posts with label Ipad. Show all posts

Thursday, March 7, 2013

NSXML Parser Tutorial (Part 3 of 3)


This is Part 3 of 3 for my NSXML Parser Tutorial. Part 1 – www.youtube.com Part 2 – www.youtube.com


Source : iphonedevx[dot]com

Introducción a la Programación en iOS

Introducción a la Programación en iOS
Objective-c
Image by Nearsoft
@ Summer Talks 2011


Source : ducktyper[dot]com

Robocat's Kickstarter campaign for Thermodo

Robocat, maker of the three iOS weather apps Haze, Outside, and Thermo, had launched a Kickstarter campaign for Thermodo, a physical thermometer that integrates with the iPhone.
While a thermometer for iOS sounds pretty clever, I believe it has some hurdles to jump in addition to getting funded. Thermodo is a tiny dongle that hangs on your keychain and plugs into the iPhone’s headphone jack.

The Kickstarter page states:

"Simply plug Thermodo into your device and start the companion app or any other Thermodo enabled apps of your choice. The temperature reading takes place instantly. Thermodo is powered by your device. No external power is required, it can even run in the background while you do important stuff."

With Robocat's own weather apps and the many other competing apps, why make Thermodo?

The Kickstarter page states:

“The reason we made this hardware actually came from the users,” Robocat told Cult of Mac. “We often got 1-star reviews from users that complain that the temperature data is incorrect or that Thermo doesn’t work indoors. So we are trying to solve this issue with a hardware module. With Thermodo they will get accurate temperature readings from where they are. It’s also just really exciting to work with hardware that can communicate with the mobile devices in a creative way.”

The software is where the magic will really happen for Thermodo. You’ll be able to quickly measure the temperature indoors and outdoors. The dongle will let you track the temperature and see how it rises and falls throughout the day. No network connection is required.

Thermodo will work with Haze and Thermo, and Robotcat will have a SDK available for developers to add support for their weather apps. The idea is that you will have a miniature weather station with you at all times.

My concern is that you will have conflicting temperatures to deal with. Let's say it is 15 degrees outside here in Detroit, but I am in my car with the temperature set at 75 degrees. What is the temperature that I want my phone to report? The external or internal temperature? I contend that you will vary on this, but the man thing is both. My biggest issue is just why? Why do I want to know the exact temperature of my immediate environment? Why would the majority of people want to know this? I am quite sure there are many specialized professions and individuals that will require this, but are there enough to justify this product? Time will tell.
Here is Robocat's Kickstarter page.

Source : iamthereforeipad[dot]com

Wednesday, March 6, 2013

El monitor de Ana Luisa (detalle)

El monitor de Ana Luisa (detalle)
Objective-c
Image by Nearsoft


Source : ducktyper[dot]com

Chrome for iOS Updated BUT it is broke

The Chrome team happily announced Chrome 25 for iPhone and iPad. Chrome 25.0.1364.86 contains a number of improvements including:

- Long press on the back button to quickly access any page in your tab history
- Share a web page via Messages

Along with these new features, over the coming days they hope to make searching on Google even easier:
- See your search term right in the omnibox, instead of the search query URL
- Easily refine your search queries and view more results on the search results page

The update will be rolled out in the App Store over the last three days, but none of us iOS user have been able to use the app since. The Chrome app crashes within seconds of launching.

This happens on all iOS device types. Hopefully Google will resolve this and hopefully Apple will quickly approve the fixed product and get it in the AppStore quickly.

Source : iamthereforeipad[dot]com

Tuesday, March 5, 2013

iPhone/iPad Development Tutorial(Introduction and First Lesson)


Important things to know before you start development, Honestly this should be the first lesson before starting development iphone development tutorial “Macworld” “expo” “steve” “jobs” “iphone” “ipod” “apple” “touchscreen” “keynote” “nano” “video” “iphone” “sdk” “development” “tutorial” “app” “store” “beginner” “getting” “started” “hello” “world” “xcode” “iphone” “sdk” “development” “programming” “objective-c” “iphone development tutorial” “app” “store” “beginner” “getting” “started” “hello” “world” “iphone” “dev” “tutorial”


Source : iphonedevx[dot]com

Objective-C Tutorial – Lesson 5: Part 2: Xcoding Decisions in your Code

Objective-C® for Dummies® by Neal Goldstein, Copyright © 2009 by Wiley Publishing, Inc., is the main source of information for this video. In this lesson we go into Xcode and try out what we learned in Part 1. Twitter – twitter.com FaceBook – www.facebook.com E-mail – macandcomputerhelp@gmail.com Objective-C Tutorial objective-c tutorial objective c tutorial
Video Rating: 4 / 5


Source : ducktyper[dot]com

ButtonHide Example in iPhone

In this application we will see how to hide button from the iPhone application. So let see how it will worked.

Step 1: Open the Xcode, Create a new project using Single View Application. Give the application
“ButtonHide”.

Step 2: Need to add new viewController class in the project. Select project -> New file ->
UIViewController subclass -> next -> Give the application name “ButtonHideView”.

Step 3: Now open the AppDelegate.h file and make the following changes:

#import <UIKit/UIKit.h>

@class ButtonHideView;

@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
ButtonHideView *buttonHideView;
}
@property (nonatomic, retain)IBOutlet ButtonHideView *buttonHideView;
@property (strong, nonatomic) UIWindow *window;

@end

Step 4: In the AppDelegate.m file make the following changes:

#import "AppDelegate.h"
#import "ButtonHideView.h"

@implementation AppDelegate

@synthesize window = _window,buttonHideView;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];

buttonHideView = [[ButtonHideView alloc]
initWithNibName:@"ButtonHideView"
bundle:nil];
[_window addSubview:buttonHideView.view];

return YES;
}

@end

Step 5: Now open the “ButtonHideView.h” file and make the following changes:

#import <UIKit/UIKit.h>

@interface ButtonHideView : UIViewController
{
IBOutlet UIButton *button1;
IBOutlet UITextField *textfield1;

}
@property (nonatomic, retain) IBOutlet UIButton *button1;
@property (nonatomic, retain) IBOutlet UITextField *textfield1;

-(IBAction) ButtonHide:(id)sender;
//}

@end

Step 6: Double click the ButtonHideView.xib file and open it to the Interface Builder. First drag the
UIButton and UITextField from the library and place it to the view window. Select the button from
the view window and bring up connection inspector and connect touch up inside to the File’s Owner
icon and select “ButtonHide:” method and connect the File’s owner icon to the textfield and select
“textfield1”. Now save the .xib file, close it and go back to the Xcode.

Step 7: In the ButtonHideView.m file make the following changes:

#import "ButtonHideView.h"

@implementation ButtonHideView

@synthesize button1,textfield1;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

-(IBAction) ButtonHide:(id)sender
{
if([textfield1.text isEqualToString: @""]){
button1.hidden = YES;

} else {
button1.hidden = NO;

}
NSLog( @"%@", textfield1.text );
}

@end

Step 8: Now Compile and run the application on the Simulator


Source : edumobile[dot]org

Monday, March 4, 2013

What are some magazines that are in print for development and programming?

Question by Teeter: What are some magazines that are in print for development and programming?
I need one that actually mails out, not online. Can be about:
* Website development
* Website programming
* Website design
* Database programming
* Linux or linux server administration
* Open source software
* Mac programming or iPhone programming (there are probably not very many of these)
* Specific languages: Java, Javascript, HTML

Best answer:

Answer by Victor
I used to subscribe to Linux magazine. Good insight on upcoming items and code snippets on hot topics. Good read. Recommended.

see:

http://www.linux-mag.com/contact

Give your answer to this question below!


Source : ducktyper[dot]com

Sunday, March 3, 2013

Objective C Tutorials 57 Creating and Using a Car Class Complete Example


Description: Objective-C video tutorials — In these programming video series I’ll go through the basics of objective-c object oriented programming language. Objective-c is the programming language of Apple Mac OSX Operating system and the language of iOS. So if you want to develop applications for Mac, iPhone, iPad, and iPod touch then you have to master objective-c programming language. It’s one of the best programming language and it’s easy to learn. It is derived from the C language but it’s Object-oriented which makes it better. These video tutorials are for beginners and gradually we’ll discuss the advanced part of objective-c as time goes on. If you have any questions drop a comment. And don’t forget to rate and like all the videos to allow others to benefit from these objective-c video tutorials.


Source : iphonedevx[dot]com

Siri, "I don't see an app named"

Every since updated my iPhone 5 and iPad 3 to iOS 6.1.2, Siri will not launch any apps except Apple own. After every other request, Siri replieswith the  response, "I don't see an app named". 


Can someone on iOS 6.1.2, please 
try to open a non-Apple app with Siri. 

Please report your results. 

Carl W. Brooks
http://www.iamthereforeipad.com

Sent from Mailbox for iPhone

Source : iamthereforeipad[dot]com

Objective-C on the Mac L13 – NSMutableArray

How to use the NSMutableArray class in Objective-C.
Video Rating: 5 / 5


Source : ducktyper[dot]com

Saturday, March 2, 2013

Gridlee Finally Removed from AppStore

We knew it was just a matter of time before Apple pulled the Gridlee app from it's U.S. AppStore. Gridlee was added into the AppStore in late January 2013 and last just over a month before it was removed.

The Gridlee game got immediate attention from the gamers who suspected that the game had more to offer because the Gridlee game sucked. The game was all the rave, not for the game Gridlee, but for what games it allow you to add.

The game was a mame. The mame allowed older arcade games' ROM or read only memory to be played if they were added to a folder called ROMs in the document folder of the Gridlee game.

The blogs that covered iOS and Apple products immediately posted stories that Apple would pull the plug in the game within days. After weeks went by, some began to suspect and even report that the game must comply to the Apple AppStore submission guidelines.

Apparently not, because as if today the Gridlee app is no longer available.




Source : iamthereforeipad[dot]com

Programming in Objective-C 2.0 (2nd Edition)

Programming in Objective-C 2.0 (2nd Edition)

THE #1 BESTSELLING BOOK ON OBJECTIVE-C 2.0

Programming in Objective-C 2.0 provides the new programmer a complete, step-by-step introduction to Objective-C, the primary language used to develop applications for the iPhone, iPad, and Mac OS X platforms.   The book does not assume previous experience with either C or object-oriented programming languages, and it includes many detailed, practical examples of how to put Objective-C to use in your everyday iPhone/iPad or Mac OS X progr

List Price: $ 44.99

Price:


Source : ducktyper[dot]com

Friday, March 1, 2013

Objective C Tutorials 34 Infinite Loop and Variable Scopes


Description: Objective-C video tutorials — In these programming video series I’ll go through the basics of objective-c object oriented programming language. Objective-c is the programming language of Apple Mac OSX Operating system and the language of iOS. So if you want to develop applications for Mac, iPhone, iPad, and iPod touch then you have to master objective-c programming language. It’s one of the best programming language and it’s easy to learn. It is derived from the C language but it’s Object-oriented which makes it better. These video tutorials are for beginners and gradually we’ll discuss the advanced part of objective-c as time goes on. If you have any questions drop a comment. And don’t forget to rate and like all the videos to allow others to benefit from these objective-c video tutorials.


Source : iphonedevx[dot]com

If you want to add data to an iphone script. What type of file do you do this with?

Question by Advice Please: If you want to add data to an iphone script. What type of file do you do this with?
Also, can you submit an iphone programmed with a windows pc? I know it has to be coded on a mac, but if someone codes it and emails you the files, can they be forwarded onto apple this way? Can the windows person fill out a data file or does that have to also be done on a mac? Say I had a list of soups I wanted to have listed on the application. Can the windows pc create that list or does it have to be a mac file?

Best answer:

Answer by Rodrigo33024
You can import data to your iphone app by creating a plist or a sqlite file, they both can be created on a PC or mac, they are just text files with the information that you will be importing.
Once you have the plist or sqlite files you need to import them to xcode in the resources folder and your iphone application will need to be programmed to open the file, read its content and display it.
You will also need to recompile your app after that.

Know better? Leave your own answer in the comments!


Source : ducktyper[dot]com

Using Toolbars in iPhone

The UINavigationController maintains a UIToolBar for each view controller in its stack. This toolbar is normally hidden, but we can place buttons on it and display it any time we want. Let’s see how this is done.

Start Xcode, select “Create a new Xcode project” and select the Empty Application template. Click Next, name the project ToolBarButtons, and choose options as shown:

Click Next, choose a location to save the project, and finally click Create. When the project has loaded, select the AppDelegate.m file, right-click that file, and select “New File” from the popup menu. (The reason we selected the AppDelegate.m file first is that Xcode will place newly created files immediately below the selected file in the navigator.)

Select the Objective-C class template, click Next, and name the class MainViewController. Make sure that the class is a subclass of UIViewController, and also create a XIB file for the controller’s view as shown:

Click Next, accept the default location, and click Create.

Now we’re going to set up a navigation controller having a MainViewController object as its root view controller. Select the AppDelegate.h file, and add the two properties for the UINavigationController and the MainViewController as shown:

#import <UIKit/UIKit.h>
#import "MainViewController.h"

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UINavigationController *navController;
@property (strong, nonatomic) MainViewController *rootViewController;

@end

Make sure that the MainViewController file is imported, otherwise we won’t be able to instantiate on object from it.
After adding the navController and rootViewController objects, Open the AppDelegate.m file, and make the following changes:

#import "AppDelegate.h"

@implementation AppDelegate

@synthesize window = _window;
@synthesize navController = _navController;
@synthesize rootViewController = _rootViewController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.rootViewController = [[MainViewController alloc] initWithNibName:nil bundle:nil];
    self.rootViewController.title = @"Main View";
    self.navController = [[UINavigationController alloc] initWithRootViewController:self.rootViewController];
    [self.window addSubview:self.navController.view];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

As always, we first synthesize our properties. We’ve only shown the application: didFinishLaunchingWithOptions: method here, because it’s the only method we will be making changes to. Leave the remaining methods in place.

First, we allocate and initialize the rootViewController. The nib name of nil in this case directs the compiler to associate this controller with the XIB file that was created with it (MainViewController.xib). A bundle of nil directs the compiler to use this application’s bundle. After we initialize this controller, we set its title to @”Main View.” This title will appear in the navigation bar for this view controller.

Next, we set up the navController object. We make rootViewController this object’s Root View Controller. Adding the navController’s view to the main window as a subview, we then make the main window key and visible, and we’re off and running.

In the MainViewController.xib file, choose a nice color for the view:

Since the view controller’s title property was set to @”Main View” in the AppDelegate, that title will appear at the top of the interface when we run the app:

Open the MainViewController.m file, and make these additions to initWithNibName: bundle:

- ( id )initWithNibName : ( NSString * )nibNameOrNil bundle : ( NSBundle * )nibBundleOrNil
{
    self = [super initWithNibName :nibNameOrNil bundle :nibBundleOrNil ];
    if (self ) {
        // Custom initialization
       
        // set up the nav bar button:
        UIBarButtonItem *btnShow = [ [UIBarButtonItem alloc ]     initWithBarButtonSystemItem :UIBarButtonSystemItemSearch target :self     action : @selector (toggleToolBar ) ];
        self.navigationItem.rightBarButtonItems = [ NSArray arrayWithObjects :btnShow, nil ];
       
        // set up the tool bar buttons:
        UIBarButtonItem *btnRed = [ [UIBarButtonItem alloc ] initWithTitle : @ "Red"         style :UIBarButtonItemStyleDone target :self action : @selector (btnRedTouched ) ];
        UIBarButtonItem *btnBlue = [ [UIBarButtonItem alloc ] initWithTitle : @ "Blue"       style :UIBarButtonItemStyleDone target :self action : @selector (btnBlueTouched ) ];
        UIBarButtonItem *spacer = [ [UIBarButtonItem alloc ]      initWithBarButtonSystemItem :UIBarButtonSystemItemFlexibleSpace target : nil action : nil ];
        UIBarButtonItem *btnGreen = [ [UIBarButtonItem alloc ] initWithTitle : @ "Green"     style :UIBarButtonItemStyleDone target :self action : @selector (btnGreenTouched ) ];
        self.toolbarItems = [ NSArray arrayWithObjects :btnRed, btnBlue, spacer, btnGreen, nil ];
       
    }
    return self;
}

First, we add a UIBarButtonSystemItemSearch button to the navigationItem’s rightBarButtonItems array. This button will be placed at the right of the top navigation bar. Next, we set up three bar buttons (btnRed, btnBlue, and btnGreen) and a spacer. The three buttons each have a selector, these will be defined shortly. Each also is initialized with a title, and a style of UIBarButtonItemStyleDone, which will produce a button with a blue background and white bolded text.

The function of the spacer is to add “flexible space” between btnBlue and btnGreen. Flexible space will act as a “spring” between the two buttons, pushing btnGreen all the way to the right of the tool bar. Since this space is invisible, it makes no sense to assign it an action method, so we have set both the target and action of this object to nil.

Now that we have the buttons, we need to add them to the tool bar. Each view controller has it’s own toolBarItems property, which is an NSArray of UIBarButtonItem objects. This line:

self.toolbarItems = [ NSArray arrayWithObjects :btnRed, btnBlue, spacer, btnGreen, nil ];

stuffs the toolBarButtons array with the three buttons and the spacer.

All that remains now is to implement the four methods we set as actions in the buttons:

- ( void )toggleToolBar
{
    BOOL barState = self.navigationController.toolbarHidden;
    [self.navigationController setToolbarHidden :!barState animated : YES ];
}

- (void)btnRedTouched
{
    self.view.backgroundColor = [UIColor redColor];
}

- (void)btnBlueTouched
{
    self.view.backgroundColor = [UIColor cyanColor];
}

- (void)btnGreenTouched
{
    self.view.backgroundColor = [UIColor greenColor];
}

toggleToolBar gets the hidden property of the tool bar, then sets that property to its negation. In other words, if the tool bar is hidden it will be shown, if it is shown it will be hidden.

The three btn…Touched methods set the color of the view’s background to red, cyan, or green when they are touched.
Run the app, and enjoy:


Source : edumobile[dot]org

Thursday, February 28, 2013

Book 1: Diving In – iOS App Development for Non-Programmers Series: The Series on How to Create iPhone & iPad Apps

Book 1: Diving In – iOS App Development for Non-Programmers Series: The Series on How to Create iPhone & iPad Apps

Review:
“Most of the books I scanned, even the ‘Dummies’ series, assumed a basic knowledge of computer programming even for iOS beginners. What I like about Kevin’s writing is that he doesn’t make any assumptions — he just takes you there — step by step.” – Lorraine Akemann – Moms With Apps

Unleash the App Developer Within!
This first book in the series from Kevin McNeish, award-winning App Developer, highly acclaimed iOS trainer and conference speaker, is specifically desi

List Price: $ 16.99

Price:


Source : ducktyper[dot]com

Wednesday, February 27, 2013

Alcorn McBride LightingPad iPad / iPhone Lighting Control Application Demo


LightingPad is the perfect tool for controlling small shows, or for installing and testing lighting systems. It’s also great for programming our LightCue Pro lighting controller. Simply connect any Art-Net compatible DMX device to your wireless network, and you have a complete lighting console in the palm of your hand. Because it’s an iPad / iPhone application, it’s incredibly simple to use. For more information, visit www.alcorn.com


Source : iphonedevx[dot]com

iOS Programming 101: Record and Play Audio using AVFoundation Framework

Editor’s note: Some of you asked us to write a tutorial about audio recording. This week, we work with Raymond Au from Purple Development to give you an introduction of AVFoundation framework. Raymond is an independent iOS developer and has recently released Voice Memo Wifi that allows users to record voice memo and share it over WiFi.

iOS provides various framework to let you work with sound in your app. One of the frameworks that you can use to play and record audio file is the AV Foundation Framework. In this tutorial, I’ll walk you through the basics of the framework and show you how to manage audio playback, as well as, recording.

To provide you with a working example, I’ll build a simple audio app that allows users to record and play audio. Our primary focus is to demonstrate the AV Foundation framework so the user interface of the app is very simple.

The AV Foundation provides easy ways to deal with audio. In this tutorial, we mainly deal with these two classes:

  • AVAudioPlayer – think of it as an audio player for playing sound files. By using the player, you can play sounds of any duration and in any audio format available in iOS.
  • AVAudioRecorder – an audio recorder for recording audio

Starting with the Project Template

First of all, create a “Single View Application” and name it as “AudioDemo”. To free you from setting up the user interface and code skeleton, you can download the project template from here.

I’ve created a simple UI for you that it only contains three buttons including “Record”, “Stop” and “Play”. The buttons are also linked up with the code.

AudioDemo Project Template

AudioDemo Project Template

Adding AVFoundation Framework

By default, the AVFoundation framework is not bundled in any Xcode project. So you have to add it manually. In the Project Navigator, select the “AudioDemo” project. In the Content Area, select “AudioDemo” under Targets and click “Build Phases”. Expand “Link Binary with Libraries” and click the “+” button to add the “AVFoundation.framework”.

Adding AVFoundation Framework

Adding AVFoundation Framework

To use the AVAudioPlayer and AVAudioRecorder class, we need to import in ViewController.h.

1
#import <AVFoundation/AVFoundation.h>


Audio Recording using AVAudioRecorder

First, let’s take a look how we can use AVAudioRecorder to record audio. Add the AVAudioRecorderDelegate protocol and AVAudioPlayerDelegate in the ViewController.h. We’ll explain both delegates as we walk through the code.

1
@interface ViewController : UIViewController <AVAudioRecorderDelegate, AVAudioPlayerDelegate>

Next, declare the instance variables for AVAudioRecorder and AVAudioPlayer in ViewController.m:

1
2
3
4
@interface ViewController ( ) {
    AVAudioRecorder *recorder;
    AVAudioPlayer *player;
}

The AVAudioRecorder class provides an easy way to record sound in iOS. To use the recorder, you have to prepare a few things:

  • Specify a sound file URL.
  • Set up the audio session.
  • Configure the audio recorder’s initial state.

We’ll do the setup in the “viewDidLoad” method of ViewController.m. Simply edit the method with the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
- ( void )viewDidLoad
{
    [super viewDidLoad ];
   
    // Disable Stop/Play button when application launches
    [stopButton setEnabled : NO ];
    [playButton setEnabled : NO ];
   
    // Set the audio file
    NSArray *pathComponents = [ NSArray arrayWithObjects :
                                [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES ) lastObject ],
                                @ "MyAudioMemo.m4a",
                                nil ];
    NSURL *outputFileURL = [ NSURL fileURLWithPathComponents :pathComponents ];
   
    // Setup audio session
    AVAudioSession *session = [AVAudioSession sharedInstance ];
    [session setCategory :AVAudioSessionCategoryPlayAndRecord error : nil ];

    // Define the recorder setting
    NSMutableDictionary *recordSetting = [ [ NSMutableDictionary alloc ] init ];
   
    [recordSetting setValue : [ NSNumber numberWithInt :kAudioFormatMPEG4AAC ] forKey :AVFormatIDKey ];
    [recordSetting setValue : [ NSNumber numberWithFloat : 44100.0 ] forKey :AVSampleRateKey ];
    [recordSetting setValue : [ NSNumber numberWithInt : 2 ] forKey :AVNumberOfChannelsKey ];
   
    // Initiate and prepare the recorder
    recorder = [ [AVAudioRecorder alloc ] initWithURL :outputFileURL settings :recordSetting error : NULL ];
    recorder.delegate = self;
    recorder.meteringEnabled = YES;
    [recorder prepareToRecord ];
}

Note: For demo purpose, we skip the error handling. In real app, don’t forget to include proper error handling.

In the above code, we first define the sound file URL for saving the recording. and then configure the audio session. iOS handles audio behaviour of an app by using audio sessions. Upon launch, your app automatically gets an audio session. You can grab such session by calling [AVAudioSession sharedInstance] and configure it. Here, we tell iOS that the app uses “AVAudioSessionCategoryPlayAndRecord” category which enables both audio input and output. We will not go into the details of audio session but you can check out the official document for further details.

The AVAudioRecorder uses a dictionary-based settings for its configuration. In line 21-25, we use the options keys to configure the audio data format, sample rate and number of channels. Lastly, we initiate the audio recorder by calling “prepareToRecord:” method.

Note: For other settings keys, you can refer to AV Foundation Audio Settings Constants.

Implementing Record Button

We’ve completed the audio preparation. Let’s move on to implement the action method of Record button. Before we dive into the code, let me explain how the “Record” button works. When user taps the “Record” button, the app will start recording and the button text will be changed to “Pause”. If user taps the “Pause” button, the app will pause the audio recording till the “Record” is tapped again. The audio recording will only be stopped when user taps the “Stop” button.

Edit the “recordPauseTapped:” method with the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
- (IBAction )recordPauseTapped : ( id )sender {
    // Stop the audio player before recording
    if (player.playing ) {
        [player stop ];
    }
   
    if ( !recorder.recording ) {
        AVAudioSession *session = [AVAudioSession sharedInstance ];
        [session setActive : YES error : nil ];
       
        // Start recording
        [recorder record ];
        [recordPauseButton setTitle : @ "Pause" forState :UIControlStateNormal ];

    } else {

        // Pause recording
        [recorder pause ];
        [recordPauseButton setTitle : @ "Record" forState :UIControlStateNormal ];
    }

    [stopButton setEnabled : YES ];
    [playButton setEnabled : NO ];
}

In the above code, we first check whether the audio player is playing. If audio player is playing, we simply stop it by using the “stop:” method. Line 7 of the above code determines if the app is in recording mode. If it’s not in recording mode, the app activates the audio sessions and starts the recording. For recording to work (or sound to play), your audio session must be active.

In general, you can use the following methods of AVAudioRecorder class to control the recording:

  • record – start/resume a recording
  • pause – pause a recording
  • stop – stop a recording

Implementing Stop Button

For the Stop button, we simply call up the “stop:” method to the recorder, followed by deactivating the audio session. Edit the “stopTapped:” method with the following code:

1
2
3
4
5
6
- (IBAction )stopTapped : ( id )sender {
    [recorder stop ];
   
    AVAudioSession *audioSession = [AVAudioSession sharedInstance ];
    [audioSession setActive : NO error : nil ];
}

Implementing the AVAudioRecorderDelegate Protocol

You can make use of AVAudioRecorderDelegate protocol to handle audio interruptions (say, a phone call during audio recording) and the completion of recording. In the example, the ViewController is the delegate. The methods defined in AVAudioRecorderDelegate protocol are optional. Here, we’ll only implement the “audioRecorderDidFinishRecording:” method to handle the completion of recording. Add the following code to ViewController.m:

1
2
3
4
5
6
- ( void ) audioRecorderDidFinishRecording : (AVAudioRecorder * )avrecorder successfully : ( BOOL )flag {
    [recordPauseButton setTitle : @ "Record" forState :UIControlStateNormal ];
   
    [stopButton setEnabled : NO ];
    [playButton setEnabled : YES ];    
}

After finishing the recording, we simply change the “Pause” button back to “Record” button.


Playing Sound using AVAudioPlayer

Finally, it comes to the implementation of the “Play” button for audio playback using AVAudioPlayer. In the ViewController.m, edit the “playTapped:” method using the following code:

1
2
3
4
5
6
7
- (IBAction )playTapped : ( id )sender {
    if ( !recorder.recording ) {
        player = [ [AVAudioPlayer alloc ] initWithContentsOfURL :recorder.url error : nil ];
        [player setDelegate :self ];
        [player play ];
    }
}

The above code is very straightforward. Normally, there are a few things to configure an audio player:

  • Initialize the audio play and Assign a sound file to it. In the case, it’s the audio file of the recording (i.e. recorder.url).
  • Designate an audio player delegate object, which handles interruptions as well as the playback-completed event.
  • Call play: method to play the sound file.

Implementing the AVAudioPlayerDelegate Protocol

The delegate of an AVAudioPlayer object must adopt the AVAudioPlayerDelegate protocol. In this case, it’s the ViewController. The delegate allows you to handle interruptions, audio decoding errors and update the user interface when an audio has finished playing. All methods in AVAudioplayerDelegate protocol are optional, however. To demonstrate how it works, we’ll implement the “audioPlayerDidFinishPlaying:” method to display an alert prompt after the completion of audio playback. For usage of other methods, you can refer to the official documentation of AUAudioPlayerDelegate protocol.

Add the following code in ViewController.m:

1
2
3
4
5
6
7
8
- ( void ) audioPlayerDidFinishPlaying : (AVAudioPlayer * )player successfully : ( BOOL )flag {
    UIAlertView *alert = [ [UIAlertView alloc ] initWithTitle : @ "Done"
                               message : @ "Finish playing the recording!"
                              delegate : nil
                     cancelButtonTitle : @ "OK"
                     otherButtonTitles : nil ];
    [alert show ];
}


Compile and Run Your App

You can test audio recording and playback using a physical device or software simulator. If you test the app using actual device (e.g. iPhone), the audio being recorded comes from the device connected by the built-in microphone or headset microphone. On the other hand, if you test the app by using the Simulator, the audio comes from the system’s default audio input device as set in the System Preference.

So go ahead to compile and run the app! Tap “Record” button to start recording. Say something, tap the “Stop” button and then select the “Play” button to listen the playback.

AudioDemo App

AudioDemo App

For your reference, you can download the complete source code from here. Feel free to leave me comment if you have any questions.

This post is contributed by Raymond Au from Purple Development. Raymond is an independent iOS developer and has recently released Voice Memo Wifi that allows users to record voice memo and share it over WiFi.


Source : appcoda[dot]com