Whilst, I have been unable to replicate this issue on my test devices / simulator, I'm getting a few crash reports from some users, but not all. EXC_BAD_ACCESS KERN_INVALID_ADDRESS at this line. Why is this and what steps can I take to resolve? The crash reports are from users on iOS 14.4.0 and 14.3.0 and from a variety of devices (iPhone 6s plus, iPhone 8 Plus, iPhone SE (2nd generation), iPhone XS, iPhone 7, iPhone 7s, iPhone 11, iPhone 12, iPhone X)
In PageViewController.m
// Voice Recording - Needed as workaround as there is a bug in AudioKit
NSArray *pathComponents = [NSArray arrayWithObjects:
                           [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
                           defaultVoiceRecording,
                           nil];
NSURL *outputFileURL = [NSURL fileURLWithPathComponents:pathComponents];
// Setup audio session to play through loud speakers
AVAudioSession *session = [AVAudioSession sharedInstance];
NSError *error;
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
if(error){
    NSLog(@"AVAudioSession Sing the Note error tuner:%@",error);
}
// Setup audio session to play through loud speakers
if (![MenuViewController areHeadphonesPluggedIn]){ // EXC_BAD_ACCESS KERN_INVALID_ADDRESS here
    
    [session overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:&error];
    if(error)
    {
        NSLog(@"Error: AudioSession cannot use speakers");
    }
}
In MenuViewController.h
+(BOOL)areHeadphonesPluggedIn;
In MenuViewController.m
+(BOOL)areHeadphonesPluggedIn {
    @try{
        NSArray *availableOutputs = [[AVAudioSession sharedInstance] currentRoute].outputs;
        for (AVAudioSessionPortDescription *portDescription in availableOutputs) {
            if ([portDescription.portType isEqualToString:AVAudioSessionPortHeadphones]) {
                return YES;
            }
        }
        return NO;
    }
    @catch(id Exception){
        return NO;
    }
}