# \[IOS\]AudioCaptureCrash (AudioCaptureAudioUnit) 4.27 source

**URL:** <https://forums.unrealengine.com/t/ios-audiocapturecrash-audiocaptureaudiounit-4-27-source/252194>\
**Category:** Mobile\
**Tags:** unreal-engine, iOS\
**Created:** [September 22, 2021, 10:50pm UTC](https://forums.unrealengine.com/t/ios-audiocapturecrash-audiocaptureaudiounit-4-27-source/252194 "2021-09-22T22:50:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![DonFrag](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DonFrag](https://forums.unrealengine.com/u/DonFrag)\
**Post date:** [September 22, 2021, 10:50pm UTC](https://forums.unrealengine.com/t/ios-audiocapturecrash-audiocaptureaudiounit-4-27-source/252194/1 "2021-09-22T22:50:58Z")

</div>

I made a game with a pawn that uses AudioCapture  
Android: Everythink ok  
Windows Everything OK  
IOS: AudioCapture always capture 0 data and when you change scene or close the app, it crashes all . If i load the pawn with the Audio CaptureComponent and i capture nothing, just stay there and then change level, or exit app, the game crash anyways.  
any solution? according to UE4 git source ios should be supported using AudioCaptureAudioUnit  
[Search · AudioCaptureAudioUnit (github.com)](https://github.com/EpicGames/UnrealEngine/search?q=AudioCaptureAudioUnit)

My app is requesting permissions with plist and making a function call (the prompt window appears at the beginning), but just the presence of the component makes everthing collapses

---

<div class="post-metadata">

**Author:** ![DonFrag](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DonFrag](https://forums.unrealengine.com/u/DonFrag)\
**Post date:** [September 29, 2021, 10:21pm UTC](https://forums.unrealengine.com/t/ios-audiocapturecrash-audiocaptureaudiounit-4-27-source/252194/2 "2021-09-29T22:21:23Z")

</div>

any help with this? i need to solve it for my job

---

<div class="post-metadata">

**Author:** ![apmason](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/apmason/32/88719_2.png) [@apmason](https://forums.unrealengine.com/u/apmason)\
**Post date:** [January 27, 2022, 8:37pm UTC](https://forums.unrealengine.com/t/ios-audiocapturecrash-audiocaptureaudiounit-4-27-source/252194/3 "2022-01-27T20:37:54Z")

</div>

Did you solve this? I’m running in to a similar issue

---

<div class="post-metadata">

**Author:** ![DonFrag](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DonFrag](https://forums.unrealengine.com/u/DonFrag)\
**Post date:** [January 28, 2022, 11:53am UTC](https://forums.unrealengine.com/t/ios-audiocapturecrash-audiocaptureaudiounit-4-27-source/252194/4 "2022-01-28T11:53:55Z")

</div>

i had to create my own solution using IOS native code

---

<div class="post-metadata">

**Author:** ![apmason](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/apmason/32/88719_2.png) [@apmason](https://forums.unrealengine.com/u/apmason)\
**Post date:** [January 28, 2022, 6:47pm UTC](https://forums.unrealengine.com/t/ios-audiocapturecrash-audiocaptureaudiounit-4-27-source/252194/5 "2022-01-28T18:47:40Z")

</div>

Thanks for the reply.  
If you don’t mind sharing, which Apple API did use? The higher level AVAudioSession, so you recorded to a file, or did you use AudioUnits to get the buffer data? Any tips?

---

<div class="post-metadata">

**Author:** ![DonFrag](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DonFrag](https://forums.unrealengine.com/u/DonFrag)\
**Post date:** [January 28, 2022, 10:12pm UTC](https://forums.unrealengine.com/t/ios-audiocapturecrash-audiocaptureaudiounit-4-27-source/252194/6 "2022-01-28T22:12:56Z")

</div>

i used AVAudioSession. first i created a small project for ios in Xcode and tested the recording. Then when it work, i move the code as plugin for UE4  
somehing like this

```auto

@implementation FIosVoiceRecorder
@synthesize recorder,recorderSettings,recorderFilePath,fileUrl;
@synthesize audioPlayer,audioFileName, filePath;

- (instancetype)init
 {
     self = [super init];
     
     return self;
 }
#pragma mark - Audio Recording
- (void)startRecording
{
    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    NSError *err = nil;
    [audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
    if(err)
    {
        NSLog(@"audioSession: %@ %ld %@", [err domain], (long)[err code], [[err userInfo] description]);
        return;
    }
    [audioSession setActive:YES error:&err];
    err = nil;
    if(err)
    {
        NSLog(@"audioSession: %@ %ld %@", [err domain], (long)[err code], [[err userInfo] description]);
        return;
    }
    NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
     NSString *docsDir = [dirPaths objectAtIndex:0];
     fileUrl = [NSURL fileURLWithPath:[docsDir stringByAppendingPathComponent:@"Mustakistmp.m4a"]];
   
   // NSURL *tmpFileUrl = [[NSURL alloc] initFileURLWithPath:filePath];
    //fileUrl = [[NSURL alloc] initFileURLWithPath:filePath];

    NSDictionary *recordSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                            [NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
                            [NSNumber numberWithFloat:16000.0], AVSampleRateKey,
                            [NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
                            nil];
    
     
    
     err = nil;
    recorder = [[AVAudioRecorder alloc] initWithURL:fileUrl settings:recordSettings error:&err];
    if(!recorder){
        NSLog(@"recorder: %@ %ld %@", [err domain], (long)[err code], [[err userInfo] description]);
        
        return;
    }
    
    //prepare to record
    [recorder setDelegate:self];
    [recorder prepareToRecord];
    recorder.meteringEnabled = YES;
    
    BOOL audioHWAvailable = audioSession.isInputAvailable;
    if (! audioHWAvailable) {
        NSLog(@"Audio input hardware not available");
     
        return;
    }
    
    // start recording
    [recorder recordForDuration:(NSTimeInterval) 60];//Maximum recording time : 60 seconds default
   
    NSLog (@"Recroding Started: %@ ",fileUrl.absoluteString);

}

- (void)stopRecording
{
    [recorder stop];
    NSLog(@"Recording Stopped");
}
#pragma mark - Audio Playing
- (void)startPlaying
{
    NSLog(@"playRecording");
        
        AVAudioSession *audioSession = [AVAudioSession sharedInstance];
        [audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
        
        NSError *error;
        audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileUrl error:&error];
        audioPlayer.numberOfLoops = 0;
        [audioPlayer play];
        NSLog(@"playing");
}

```

this is not the complete code so it won’t correctly but i hope you get the idea.

---

<div class="post-metadata">

**Author:** ![apmason](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/apmason/32/88719_2.png) [@apmason](https://forums.unrealengine.com/u/apmason)\
**Post date:** [January 28, 2022, 10:50pm UTC](https://forums.unrealengine.com/t/ios-audiocapturecrash-audiocaptureaudiounit-4-27-source/252194/7 "2022-01-28T22:50:24Z")

</div>

Yes that makes sense, thank you!

---

<div class="post-metadata">

**Author:** ![DonFrag](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DonFrag](https://forums.unrealengine.com/u/DonFrag)\
**Post date:** [January 28, 2022, 11:27pm UTC](https://forums.unrealengine.com/t/ios-audiocapturecrash-audiocaptureaudiounit-4-27-source/252194/8 "2022-01-28T23:27:47Z")

</div>

No problem
