I developed an iPhone app under iOS 5.0, and it works fine. But when it comes to iOS 4.3(Base SDK = latest iOS 5.0, compiler = Apple LLVM 3.0, Deployment Target = iOS 4.3), it crashes after launching.
The output around crash point looks like:
2011-12-06 16:25:08.177 FMWei[466:c203] -[AVAudioSession setMode:error:]: unrecognized selector sent to instance 0x706a7f0
2011-12-06 16:25:08.181 FMWei[466:c203] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AVAudioSession setMode:error:]: unrecognized selector sent to instance 0x706a7f0'
It looks like that AVAudioSession doesn’t have a member function setMode:error: while I invoked it. But what’s strange is that I didn’t invoke a function whose name is setMode:error:. The code about audio processing is:
audio_session = [[AVAudioSession sharedInstance] retain];
audio_session_err = nil;
[audio_session setCategory: AVAudioSessionCategoryPlayAndRecord error:&audio_session_err];
NSLog(@"!");
UInt32 audioRouteOverride = 1;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryDefaultToSpeaker,sizeof (audioRouteOverride),&audioRouteOverride);
UInt32 allowMixing = 1;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(allowMixing), &allowMixing);
if (audio_session_err)
{
NSLog(@"audioSession: %@ %d %@", [audio_session_err domain], [audio_session_err code], [audio_session_err description]);
}
else
{
audio_session_err = nil;
[audio_session setActive:YES error:&audio_session_err];
if (!audio_session_err) NSLog(@"audio session is activated successfully");
}
Please help me figure out why it crashes under iOS 4.3 with the strange error. Thank you!
At runtime, lots of methods are called that are not in your code, but which are called behind the scenes as a result of the API calls you have made.
I would focus not on the method that is being called, but on why the object it is sent to is unable to respond to the selector. The object could have been cast as the wrong type, and so is not inheriting the right methods. (In the code snippet you show, you don’t explicitly cast
AVAudioSession *audio_session.) The other direction is to check that you’re not using some other API call that is iOS 5 only, which in the background is calling this method and thus generating the error.Finally, if you’re only recently changed your build target to include iOS 4.3, you may simply need to do a clean build (Product > Clean) so that it compiles iOS 4.3-compatible code.