Bug 42608 - AVAudioEngine.InputNode access causes silent crash
Summary: AVAudioEngine.InputNode access causes silent crash
Status: RESOLVED FEATURE
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 9.99 (iOS 10 previews)
Hardware: PC Mac OS
: --- normal
Target Milestone: Xcode8 (iOS10)
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-07-15 21:29 UTC by Larry O'Brien
Modified: 2016-08-05 13:29 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FEATURE

Description Larry O'Brien 2016-07-15 21:29:15 UTC
I believe that a newly-initialized AVAudioEngine should generally have a non-null InputNode. For instance, in Swift,  

let audioEngine = AVAudioEngine()
guard let inputNode = audioEngine.inputNode else { fatalError("Audio engine has no input node") }
       
results in a valid inputNode. However, attempts to access AVAudioEngine.InputNode lead to a crash (with no apparent way to catch an exception).

To reproduce in a Xamarion.iOS solution: 

var engine = new AVAudioEngine();
var input = engine.InputNode;
if (input == null) //etc....

The system will crash before the null check.
Comment 1 Larry O'Brien 2016-08-04 20:15:36 UTC
It looks like this is caused if the following keys are not in info.plist:

<key>NSMicrophoneUsageDescription</key>
	<string>Your microphone will be used to record your speech when you press the "Start Recording" button.</string>
	<key>NSSpeechRecognitionUsageDescription</key>
	<string>Speech recognition will be used to determine which words you speak into this device's microphone.</string>
Comment 2 Manuel de la Peña [MSFT] 2016-08-05 06:59:24 UTC
As per apple docs:

/quote
NSMicrophoneUsageDescription

NSMicrophoneUsageDescription (String - iOS) This key lets you describe the reason your app accesses any of the the device’s microphones. When the system prompts the user to allow access, this string is displayed as part of the alert.

Important: To protect user privacy, an iOS app linked on or after iOS 10.0, and which accesses any of the device’s microphones, must statically declare the intent to do so. Include the NSMicrophoneUsageDescription key in your app’s Info.plist file and provide a purpose string for this key. If your app attempts to access any of the device’s microphones without a corresponding purpose string, your app exits.
This key is supported in iOS 7.0 and later.

/endquote

Was this happening in iOS 10 for you? If that is the case the fact that the app exits is a feature (go figure, I'd expect some kind of feedback!).
Comment 3 Larry O'Brien 2016-08-05 13:29:28 UTC
Yes, this was on iOS 10. I guess "If your app attempts to access any of the device’s microphones without a corresponding purpose string, your app exits." is a "feature" but holy cow I wish we could diagnose it.