Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8492737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:48:35+00:00 2026-06-10T22:48:35+00:00

Hi I have a very strange problem in the simulator works perfect but when

  • 0

Hi I have a very strange problem in the simulator works perfect but when I charge the app to the iPad it does not work. Any idea?

Here I create all the variables to make it work.

- (void)viewDidLoad {

[super viewDidLoad];

NSArray *dirPaths;
NSString *docsDir;

dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
NSString *soundFilePath = [docsDir stringByAppendingPathComponent:@"sound.caf"];

NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];

NSDictionary *recordSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                [NSNumber numberWithInt:AVAudioQualityMin],
                                AVEncoderAudioQualityKey,
                                [NSNumber numberWithInt:16],
                                AVEncoderBitRateKey,
                                [NSNumber numberWithInt: 2],
                                AVNumberOfChannelsKey,
                                [NSNumber numberWithFloat:44100.0],
                                AVSampleRateKey,
                                nil];

NSError *error = nil;

audioRecorder = [[AVAudioRecorder alloc] initWithURL:soundFileURL
                                            settings:recordSettings
                                               error:&error];
if (error)
{
    NSLog(@"error: %@", [error localizedDescription]);
} else {
    [audioRecorder prepareToRecord];
}

}

I have some buttons for record, play and stop. So these are the codes for all of them.

-(void) recordAudio{
if (!audioRecorder.recording){
    recordButton.enabled = NO;
    playButton.enabled = NO;
    saveButton.enabled = NO;
    stopButton.enabled = YES;
    [audioRecorder record];
}
}

-(void)stop{
recordButton.enabled = YES;
playButton.enabled = YES;
saveButton.enabled = YES;
stopButton.enabled = NO;    
if (audioRecorder.recording){
    [audioRecorder stop];
}
else if (audioPlayer.playing){
    [audioPlayer stop];
}
}


-(void) playAudio{
if (!audioRecorder.recording){
    recordButton.enabled = NO;
    stopButton.enabled = YES;
    saveButton.enabled = NO;        
    if (audioPlayer)
        audioPlayer=nil;
    NSError *error;

    audioPlayer = [[AVAudioPlayer alloc]
                   initWithContentsOfURL:audioRecorder.url
                   error:&error];

    audioPlayer.delegate = self;

    if (error)
        NSLog(@"Error: %@", [error localizedDescription]);
    else
        [audioPlayer play];
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:48:36+00:00Added an answer on June 10, 2026 at 10:48 pm

    finally I found a solution. To my previous code I add this lines inside the ViewdidLoad.

    AVAudioSession * audioSession = [AVAudioSession sharedInstance];
    [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error: &error];
    [audioSession setActive:YES error: &error];
    

    and for the settings I added this:

    [NSNumber numberWithInt:kAudioFormatAppleIMA4], AVFormatIDKey
    

    I copy the code from http://www.iphoneam.com/blog/index.php?title=using-the-iphone-to-record-audio-a-guide&more=1&c=1&tb=1&pb=1 and the idea of using AVAudioSession came from How to record and play sound in iPhone app?

    If you need the complete code is this one.

    - (void)viewDidLoad {
    
    [super viewDidLoad];
    
    NSError *error = nil;
    
    AVAudioSession * audioSession = [AVAudioSession sharedInstance];
    [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error: &error];
    [audioSession setActive:YES error: &error];
    
    playButton.enabled = NO;
    stopButton.enabled = NO;
    saveButton.enabled = NO;
    
    NSArray *dirPaths;
    NSString *docsDir;
    
    dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    docsDir = [dirPaths objectAtIndex:0];
    docsDir = [HSAudioController pathToDocumentsFolder];
    NSString *soundFilePath = [docsDir stringByAppendingPathComponent:@"sound.caf"];
    
    NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
    
    NSDictionary *recordSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                    [NSNumber numberWithInt:kAudioFormatAppleIMA4], AVFormatIDKey,
                                    [NSNumber numberWithInt:AVAudioQualityMin], AVEncoderAudioQualityKey,
                                    [NSNumber numberWithInt:16], AVEncoderBitRateKey,
                                    [NSNumber numberWithInt: 2], AVNumberOfChannelsKey,
                                    [NSNumber numberWithFloat:44100.0], AVSampleRateKey,
                                    nil];
    
    audioRecorder = [[AVAudioRecorder alloc] initWithURL:soundFileURL
                                                settings:recordSettings
                                                   error:&error];
    NSLog(@"%@",audioRecorder.url);
    if (error)
    {
        NSLog(@"error: %@", [error localizedDescription]);
    } else {
        [audioRecorder prepareToRecord];
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have encountered a very strange class not found problem in our web app
I experience a very strange problem and I don't have found any help to
Very strange problem with my iPhone App. We have an App that has been
I have this very strange problem on a big flex app where it would
I have a very strange problem with #any? printing true for an array that
I have a very strange problem in my app which only happen on Retina
I have a very strange problem. The required validation inside a datatable works great
i have a very strange problem, well not really a problem because i've fixed
I have very strange problem while I am submitting a practice problem on codechef.
I have a very strange problem when I'm testing my application on device. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.