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),
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.