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),
The AVAudioSession
method
- (BOOL)setMode:(NSString *)theMode error:(NSError **)outError
Is marked in the documentation as being available only for iOS 5 and later. In fact given the recent addition of modes to the documentation, it looks like audio session modes are not available at all prior to iOS 5.
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.
Maybe you can try the code snippet below
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&sessionError];
NSError * audio_session_err = nil;
[audio_session setCategory: AVAudioSessionCategoryPlayAndRecord error:&audio_session_err];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&audio_session_err];
[[AVAudioSession sharedInstance] setDelegate:self];
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;
[[AVAudioSession sharedInstance] setActive:YES error:&audio_session_err];
if (!audio_session_err) NSLog(@"audio session is activated successfully");
}
I think audio_session = [[AVAudioSession sharedInstance] retain];
dispatchs the method setMode:
by default. And the setMode:
is only available in iOS 5.0 and later(refer to the Doc).
Or you can try to comment out the code:
UInt32 audioRouteOverride = 1;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryDefaultToSpeaker,sizeof (audioRouteOverride),&audioRouteOverride);
UInt32 allowMixing = 1;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(allowMixing), &allowMixing);
There must be a method dispatches the setMode:
by default. Try yourself. :p
Try info malloc 0x706a7f0
in your gdb to get the object that the selector was sent to. Note, the 0x706a7f0
is the address that shown in your crash output as the one in your first code snippet.
And another tip, you might do make clean
(Poduct->Clean) and rebuild
it.