How to search the error code of 'com.apple.coreaudio.avfaudio'? - avaudioengine

Where could I get the information of com.apple.coreaudio.avfaudio error codes, such as:
Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'error -50'
I always get an error while writing PCM buffer to AVAudioFile. The buffer comes from AVAudioEngine's output node.
The error:
* Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'error -50'
* First throw call stack:
(0x18eb46fe0 0x18d5a8538 0x18eb46eb4 0x1a8d051cc 0x1a8d731dc 0x1000d45e0 0x1000d4820 0x1a8d14654 0x1a8d146c0 0x1a8d8c26c 0x1a8d8c1fc 0x100ae5a10 0x100af1a84 0x100b001f8 0x100ae7a60 0x100af3128 0x100ae9634 0x100af5630 0x100af6f48 0x18dc0968c 0x18dc0959c 0x18dc06cb4)
libc++abi.dylib: terminating with uncaught exception of type NSException
Could you help me?

https://www.osstatus.com/search/results?platform=all&framework=all&search=-50
I found the link just now.
You can see all the error code of apple coding

I didn't find the exact description of the error but it seems to be a generic "invalid parameters" exception.
In my case, and very likely in your case too, the issue was a mismatch between the buffer and the format of the AVAudioFile instance.
let settings: [String: Any] = [
AVFormatIDKey: kAudioFormatLinearPCM,
AVSampleRateKey: 44 * 1000,
AVNumberOfChannelsKey: 2
]
do {
try avFile = AVAudioFile(forWriting: URLFor(filename: "test.caf"), settings: settings)
avEngine.inputNode?.installTap(onBus: 0, bufferSize: 1024, format: avEngine.mainMixerNode.outputFormat(forBus: 0)) {
buffer, time in
do {
try self.avFile?.write(from: buffer)
}
catch {
// TODO
}
}
try avEngine.start()
} catch {
// TODO
}
In the example below I was getting the "-50" error when I created the AVAudioFile in any format other than PCM, 2channel 44khz.

I had a similar issue, where I was getting a com.apple.coreaudio.avfaudio -50 error with mismatched sample rates. I just had to set the AVAudioFile to match the mainMixerNode outputFormat.
let format = engine.mainMixerNode.outputFormat(forBus: 0)
self.musicTrackFinalOutputFile = try AVAudioFile(forWriting: temporaryFileURL, settings: [
AVFormatIDKey: NSNumber(value:kAudioFormatMPEG4AAC),
AVEncoderAudioQualityKey : AVAudioQuality.high.rawValue,
AVEncoderBitRateKey : 320000,
AVNumberOfChannelsKey: format.channelCount,
AVSampleRateKey : format.sampleRate
])

Related

Reading eID with NFC crushing in production build but it works in debug mode

I have a React-Native application and I implemented a 3rd party eID NFC Reader SDK. This 3rd SDK is using NFCPassportReader library and CoreNFC package also. I'm trying to read Turkish Citizenship eID with this module. My problem this module is working properly in debug mode but It's crushing in release version. I've added a crush log related to this issue and I've added tagReaderSession implementation code. I've added my "com.apple.developer.nfc.readersession.iso7816.select-identifiers" configuration code also.
Does anybody have an idea about that problem?
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000000
Exception Codes: 0x0000000000000001, 0x0000000000000000
VM Region Info: 0 is not in any region. Bytes before following region: 4340301824
REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
UNUSED SPACE AT START
--->
__TEXT 102b3c000-10603c000 [ 53.0M] r-x/r-x SM=COW ...ePieMobileDev
Termination Reason: SIGNAL 11 Segmentation fault: 11
Terminating Process: exc handler [9236]
Triggered by Thread: 8
Thread 8 name: Dispatch queue: com.apple.corenfc.readersession.delegate
Thread 8 Crashed:
public func tagReaderSession(_ session: NFCTagReaderSession, didDetect tags: [NFCTag]) {
Log.debug( "tagReaderSession:didDetect - \(tags[0])" )
if tags.count > 1 {
Log.debug( "tagReaderSession:more than 1 tag detected! - \(tags)" )
let errorMessage = NFCViewDisplayMessage.error(.MoreThanOneTagFound)
self.invalidateSession(errorMessage: errorMessage, error: NFCPassportReaderError.MoreThanOneTagFound)
return
}
let tag = tags.first!
var passportTag: NFCISO7816Tag
switch tags.first! {
case let .iso7816(tag):
passportTag = tag
default:
Log.debug( "tagReaderSession:invalid tag detected!!!" )
let errorMessage = NFCViewDisplayMessage.error(NFCPassportReaderError.TagNotValid)
self.invalidateSession(errorMessage:errorMessage, error: NFCPassportReaderError.TagNotValid)
return
}
// Connect to tag
Log.debug( "tagReaderSession:connecting to tag - \(tag)" )
session.connect(to: tag) { [unowned self] (error: Error?) in
if error != nil {
Log.debug( "tagReaderSession:failed to connect to tag - \(error?.localizedDescription ?? "Unknown error")" )
let errorMessage = NFCViewDisplayMessage.error(NFCPassportReaderError.ConnectionError)
self.invalidateSession(errorMessage: errorMessage, error: NFCPassportReaderError.ConnectionError)
return
}
Log.debug( "tagReaderSession:connected to tag - starting authentication" )
self.updateReaderSessionMessage( alertMessage: NFCViewDisplayMessage.authenticatingWithPassport(0) )
self.tagReader = TagReader(tag:passportTag)
if let newAmount = self.dataAmountToReadOverride {
self.tagReader?.overrideDataAmountToRead(newAmount: newAmount)
}
self.tagReader!.progress = { [unowned self] (progress) in
if let dgId = self.currentlyReadingDataGroup {
self.updateReaderSessionMessage( alertMessage: NFCViewDisplayMessage.readingDataGroupProgress(dgId, progress) )
} else {
self.updateReaderSessionMessage( alertMessage: NFCViewDisplayMessage.authenticatingWithPassport(progress) )
}
}
DispatchQueue.global().async {
self.startReading( )
}
}
}
<key>NFCReaderUsageDescription</key>
<string>Read the NFC chip of ePassports</string>
<key>com.apple.developer.nfc.readersession.iso7816.select-identifiers</key>
<array>
<string>A0000002471001</string>
</array>
Video recording of this issue:
https://vimeo.com/784270897
I can run the application in debug mode without any problems, but when I start reading nfc in release mode, the application crashes.

Connect multiple AVAudioMixerNodes to AVAudioEngine

I'm having a crash when I try connecting two AVAudioMixerNodes to the microphone input of AVAudioEngine.
I couldn't find documentation online how to manage two or more nodes to the same input.
What is the proper way to handle that case where you have multiple node listening to the microphone?
I'm calling those three method of after the other on the background thread:
private func setupSession() {
let session = AVAudioSession.sharedInstance()
do {
try session.setCategory(.playAndRecord, options: [.mixWithOthers])
if session.isInputGainSettable {
try session.setInputGain(0.2)
}
try session.setActive(true, options: .notifyOthersOnDeactivation)
} catch let error as NSError {
LoggerManager.shared.error(error: error, message: "Error while setting up AVAudioSession Category/Active status")
}
}
private func setupMixerNodes() {
analyzerNode = AVAudioMixerNode()
analyzerNode.volume = 0
volumeNode = AVAudioMixerNode()
volumeNode.volume = 0
engine.attach(analyzerNode)
engine.attach(volumeNode)
}
private func makeConnections() {
/* input microphone */
let inputNode = engine.inputNode
let inputFormat = inputNode.outputFormat(forBus: 0)
let analyzerConnectionPoint = AVAudioConnectionPoint(node: analyzerNode, bus: 0)
let volumeConnectionPoint = AVAudioConnectionPoint(node: volumeNode, bus: 0)
engine.connect(inputNode, to: [analyzerConnectionPoint, volumeConnectionPoint], fromBus: 0, format: inputFormat)
let mainMixerNode = engine.mainMixerNode
let mixerFormat = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: inputFormat.sampleRate, channels: 1, interleaved: false)
engine.connect(analyzerNode, to: mainMixerNode, fromBus: 0, toBus: 0, format: mixerFormat)
engine.connect(volumeNode, to: mainMixerNode, fromBus: 0, toBus: 1, format: mixerFormat)
}
and I get this crash:
AURemoteIO.cpp:1128 failed: -10851 (enable 1, outf< 2 ch, 0 Hz, Float32, deinterleaved> inf< 2 ch, 0 Hz, Float32, deinterleaved>)
2022-03-08 12:59:57.950612-0500 SnoreLabo[2914:456147] [avae] AVAEInternal.h:76 required condition is false: [AVAudioEngineGraph.mm:2401:ConnectMultipleOutputs: (IsFormatSampleRateAndChannelCountValid(format))]
2022-03-08 12:59:58.030789-0500 SnoreLabo[2914:456147] *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: IsFormatSampleRateAndChannelCountValid(format)'
*** First throw call stack:
(0x18273ed3c 0x199aa36a8 0x1828085bc 0x1ddf44eac 0x1ddf9b020 0x1de01bfa0 0x1de018328 0x104d4db1c 0x104d4e1f8 0x104ed4f6c 0x104bcdbe8 0x10dc00718 0x10dc01f94 0x10dc13edc 0x10dc146fc 0x1dcc4ae48 0x1dcc4a9f0)
libc++abi: terminating with uncaught exception of type NSException
dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
*** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: IsFormatSampleRateAndChannelCountValid(format)'
terminating with uncaught exception of type NSException
EDIT
I ended up using this:
print("Current category: \(AVAudioSession.sharedInstance().category)")
engine.connect(inputNode, to: [analyzerConnectionPoint, volumeConnectionPoint], fromBus: 0, format: inputFormat)
But I still get the same crash from time to time... And the category is properly set to .playAndRecord when it crash so that's not the issue...

error while connecting input node to AVAudioSinkNode

I get an error when connecting nodes
let sourceNode = AVAudioSinkNode { (test1, frameCount, audioBufferList) -> OSStatus in
print("callback", self.testInteger)
return noErr
}
audioEngine.attach(sourceNode)
audioEngine.connect(audioEngine.inputNode, to: sourceNode, format: nil)
[aurioc] AURemoteIO.cpp: 1086: Initialize: failed: -10851 (enable 1, outf <2 ch, 0 Hz, Float32, non-inter> inf <2 ch, 0 Hz, Float32, non-inter>)
And after that errors when try audioEngine.start ()
[avae] AVAEInternal.h: 88 required condition is false: [AVAudioEngineGraph.mm:1415:Initialize: (IsFormatSampleRateAndChannelCountValid (inputHWFormat))]
[avae] AVAudioEngine.mm:160 Engine # 0x2836a8940: could not initialize, error = -10875
[avae] AVAEInternal.h: 88 required condition is false: [AVAudioEngineGraph.mm:1415:Initialize: (IsFormatSampleRateAndChannelCountValid (inputHWFormat))]
I also tried
audioEngine.connect (audioEngine.inputNode, to: sourceNode, format: audioEngine.inputNode.inputFormat (forBus: 0))
and
audioEngine.connect (audioEngine.inputNode, to: sourceNode, format: audioEngine.inputNode.outputFormat (forBus: 0))
in these two cases the application crashes with an error
"Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: IsFormatSampleRateAndChannelCountValid (format)"
I found the problem it was necessary to put the category of the audio session playAndRecord
try audioSession.setCategory (.playAndRecord, mode: .spokenAudio, options: .defaultToSpeaker)
under this condition, this option works
audioEngine.connect (audioEngine.inputNode, to: sourceNode, format: audioEngine.inputNode.inputFormat (forBus: 0))

How to handle connection loss uploading to Firebase iOS?

I have a frontend Swift application in which users are to upload large videos and photos to Firebase Storage. I am currently working on error handling. The documentation does a good job of explaining error handling from Google's sever side of things, however it does not cover how to deal with connection loss.
This is the error handling directly from the documentation:
...
// Upload file and metadata to the object 'images/mountains.jpg'
let uploadTask = storageRef.putFile(from: localFile, metadata: metadata)
uploadTask.observe(.failure) { snapshot in
if let error = snapshot.error as? NSError {
switch (StorageErrorCode(rawValue: error.code)!) {
case .objectNotFound:
// File doesn't exist
break
case .unauthorized:
// User doesn't have permission to access file
break
case .cancelled:
// User canceled the upload
break
/* ... */
case .unknown:
// Unknown error occurred, inspect the server response
break
default:
// A separate error occurred. This is a good place to retry the upload.
break
}
}
}
I have done some tests on my device where the upload begins with no network connection. The following gets automatically printed to the console every second or so after the network goes down:
2020-07-06 01:38:28.361559-0700 Rage[12281:1978025] Connection 9: failed to connect 1:50, reason -1
2020-07-06 01:38:28.361648-0700 Rage[12281:1978025] Connection 9: encountered error(1:50)
2020-07-06 01:38:28.366906-0700 Rage[12281:1978025] Task <320E9387-F725-4AEA-B3BE-76425F73F9F7>.<6> HTTP load failed, 0/0 bytes (error code: -1009 [1:50])
2020-07-06 01:38:28.368381-0700 Rage[12281:1978042] Task <320E9387-F725-4AEA-B3BE-76425F73F9F7>.<6> finished with error [-1009] Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo={_kCFStreamErrorCodeKey=50, NSUnderlyingError=0x280a581e0 {Error Domain=kCFErrorDomainCFNetwork Code=-1009 "(null)" UserInfo={_kCFStreamErrorCodeKey=50, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <320E9387-F725-4AEA-B3BE-76425F73F9F7>.<6>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <320E9387-F725-4AEA-B3BE-76425F73F9F7>.<6>"
), NSLocalizedDescription=The Internet connection appears to be offline., NSErrorFailingURLStringKey=https://firebasestorage.googleapis.com/v0/b/rage-5940.appspot.com/o/event%2FBEC3B24F-5F97-4B6A-8FD3-5DC2F7D37AFB.mp4?uploadType=resumable&name=event%2FBEC3B24F-5F97-4B6A-8FD3-5DC2F7D37AFB.mp4, NSErrorFailingURLKey=https://firebasestorage.googleapis.com/v0/b/rage-5940.appspot.com/o/event%2FBEC3B24F-5F97-4B6A-8FD3-5DC2F7D37AFB.mp4?uploadType=resumable&name=event%2FBEC3B24F-5F97-4B6A-8FD3-5DC2F7D37AFB.mp4, _kCFStreamErrorDomainKey=1}
Is this Firebase throwing these errors? If so they are probably being thrown trying to create a storageRef before the uploadTask could even begin, and thus escape any provided error handling.
Is there anyway to catch these network errors?
Did you try this?
if error._code == NSURLErrorNetworkConnectionLost {
}
there are a couple of more you can check with them:
NSURLErrorTimedOut
NSURLErrorNotConnectedToInternet
NSURLErrorCannotConnectToHost

Firebase Authentication with phoneNumber failed with Internal error

I want to use Firebase SMS Authentication with phone number.
I have already enabled push notification in my app setting and registered Firebase Apns authentication key as google document says.
However, after I sent phone number with country code, Xcode says,
Failed to receive remote notification to verify app identity within 5
second(s)
Error says as below:
error: Error Domain=FIRAuthErrorDomain Code=17999 "An internal error has occurred, print and inspect the error details for more information." UserInfo={error_name=ERROR_INTERNAL_ERROR, NSLocalizedDescription=An internal error has occurred, print and inspect the error details for more information., NSUnderlyingError=0x28329c8a0 {Error Domain=FIRAuthInternalErrorDomain Code=3 "(null)" UserInfo={FIRAuthErrorUserInfoDeserializedResponseKey={
code = 500;
errors = (
{
domain = global;
message = "Internal error encountered.";
reason = backendError;
}
);
message = "Internal error encountered.";
status = INTERNAL;
}}}}
My code:
PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber, uiDelegate: nil) { verificationId, error in
if let error = error {
print("error: \(error)")
return
}
print("verificationId: \(verificationId!)")
UserDefaults.standard.set(verificationId, forKey: "authVerificationID")
self.goToSecondVC()
}
Any idea??