Apple did not post any alternative code for this on the Apple Developer site.
You should use AVAudioSession.
To replace the functionality provided by deprecated AudioSessionInitialize (e.g. if you need to specify AudioSessionInterruptionListener callback) you can subscribe for AVAudioSessionInterruptionNotification notification:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioSessionDidChangeInterruptionType:)
name:AVAudioSessionInterruptionNotification object:[AVAudioSession sharedInstance]];
And implement your audioSessionDidChangeInterruptionType: handler like:
- (void)audioSessionDidChangeInterruptionType:(NSNotification *)notification
{
AVAudioSessionInterruptionType interruptionType = [[[notification userInfo]
objectForKey:AVAudioSessionInterruptionTypeKey] unsignedIntegerValue];
if (AVAudioSessionInterruptionTypeBegan == interruptionType)
{
}
else if (AVAudioSessionInterruptionTypeEnded == interruptionType)
{
}
}
1. for this code
AudioSessionInitialize( NULL, NULL, interruptionCallback, self );
replace with
[[AVAudioSession sharedInstance] setActive:YES error:nil];
2. fro this code
UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord;
AudioSessionSetProperty(
kAudioSessionProperty_AudioCategory,
sizeof(sessionCategory),
&sessionCategory
);
replace with
UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord;
[[AVAudioSession sharedInstance]
setCategory:sessionCategory error:nil];
The equivalent code to
// C way
UInt32 category = kAudioSessionCategory_MediaPlayback ;
OSStatus result = AudioSessionSetProperty(
kAudioSessionProperty_AudioCategory, sizeof(category), &category ) ;
if( result ) // handle the error
Is
// Objective-C way
NSError *nsError;
[[AVAudioSession sharedInstance]
setCategory:AVAudioSessionCategoryPlayback error:&nsError];
if( nsError != nil ) // handle the error
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With