views:

739

answers:

2

I am building an iPhone audio app using Audio Sessions. Prototype was functioning till I decided to upgrade to 3.1

After a lot of hunting I finally found that the session activation call was failing with error code 12986. I havent been able to find the reason for this anywhere. The NSError object doesnt give any detail. I used the localized* APIs to get more info and this is what I got:

localizedDescription: Operation could not be completed. (OSStatus error -12986.) localizedFailureReason: <blank>

localizedRecoverySuggestion: <blank>

Anyone know how to find more info about such error codes?

Meanwhile I will continue to dig and update this if my status changes.

My Code for the curious is -

NSError *myErr;
    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&myErr];
bSuccess= [audioSession setActive: YES error: &myErr];
A: 

I've had similar trouble trying to extract useful information from the error object as well when doing core data operations, i found the following code to be helpful in determining more precisely the cause of an error.

NSError *error;

... your code here ...

NSArray* detailedErrors = [[error userInfo] objectForKey:NSDetailedErrorsKey];
if(detailedErrors != nil && [detailedErrors count] > 0) 
{
    for(NSError* detailedError in detailedErrors) 
    {
        NSLog(@"  DetailedError: %@", [detailedError userInfo]);
    }
}
else 
{
    NSLog(@"  %@", [error userInfo]);
}

Sorry i couldn't help you out with your audio problem.

HTH

Chris1Shop
do this instead: NSError *error = nil;
slf
NSDetailedErrorsKey seems to have been discontinued in 3.1 :-( It is not listed in the reference and does not compile.And it is not documented at http://developer.apple.com/iphone/library/releasenotes/General/iPhone31APIDiffs/index.html
Master Chief
My apologies, it appears that the NSDetailedErrorsKey is for core data only. As it is in the CoreDataErrors.h file.
Chris1Shop
@slf - no, never do that.
mustISignUp
@mustISignUp Listing 2-1 http://developer.apple.com/mac/library/documentation/cocoa/conceptual/ErrorHandlingCocoa/CreateCustomizeNSError/CreateCustomizeNSError.html
slf
@slf the word from bbum himself... http://www.cocoabuilder.com/archive/cocoa/204665-should-method-set-nserror-to-nil-when-no-error.html
mustISignUp
+2  A: 

Dont know what 12986 means exactly but it appears to be tied to the audio capabilities of the device now. And I have a solution!

I noticed that this error was popping up only when I use an iTouch and not on the IPhone. Since I was setting the session category as PlayAndRecord on both I decided to check if that was messing it up on the iTouch. Made the code a little smarter to detect if AudioInputIsAvailable and then set the Category accordingly (PlayBack on ITouch and PlayAndRecord on iPhone). That fixed it!

So it looks like this was being ignored in the prior SDKs. I had not changed anything earlier. :-)

Corrected Code Below:

NSError *myErr;
BOOL bSuccess = FALSE;
BOOL bAudioInputAvailable = FALSE;

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
bAudioInputAvailable= [audioSession inputIsAvailable];

if( bAudioInputAvailable)
{
 [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&myErr];
}
else {
 [audioSession setCategory:AVAudioSessionCategoryPlayback error:&myErr];
}
bSuccess= [audioSession setActive: YES error: &myErr]; 

if(!bSuccess)
{
 NSLog(@"Unable to Start Audio Session. Terminate Application.");
 NSLog([myErr localizedDescription]);
 NSLog([myErr localizedFailureReason]);
 NSLog([myErr localizedRecoverySuggestion]);
}
Master Chief
Thank you very much, I had a feeling the lack of a mic had something to do with it. The user's iPod is failing with the same error in AudioUnitInitialize. I'm pretty sure that smarter session handling will sort this out for me.
Rhythmic Fistman