I have a keyboard in my iOS Morse Code app that has always been able to play audio via AVAudioEngine. Recently it has been failing to produce audio. I see that startAndReturnError: is now failing with this error:
Error Domain=com.apple.coreaudio.avfaudio Code=268435459 "(null)" UserInfo={failed call=err = PerformCommand(*outputNode, kAUInitialize, NULL, 0)}
What's going on? Have keyboards lost the ability to play audio? Here's how I set things up:
_engine = [AVAudioEngine new];
_prefs = [[NSUserDefaults alloc] initWithSuiteName:kSharedAppGroupID];
AVAudioMixerNode* mainMixerNode = _engine.mainMixerNode;
AVAudioOutputNode* outputNode = _engine.outputNode;
AVAudioFormat* format = [outputNode inputFormatForBus:0];
AVAudioFormat* inputFormat = [[AVAudioFormat alloc] initWithCommonFormat:AVAudioPCMFormatFloat32 sampleRate:44100 channels:1 interleaved:NO];
self.srcNode = [[AVAudioSourceNode alloc] initWithRenderBlock:^OSStatus(BOOL* _Nonnull isSilence, const AudioTimeStamp* _Nonnull timestamp, AVAudioFrameCount frameCount, AudioBufferList* _Nonnull outputData) {
// This block builds the data, but is never called, so it is not the culprit.
}];
[_engine attachNode:self.srcNode];
[_engine connect:self.srcNode to:mainMixerNode format:inputFormat];
[_engine connect:mainMixerNode to:_engine.outputNode format:nil];
[_engine prepare];