AVAudio Session Delegate Deprecated iOS 6 - cocos2d-2.0-x-2.0.3

AVAudio Session Delegate Deprecated iOS 6 - cocos2d-2.0-x-2.0.3
0.0 0


When compiling my iOS 6 project with cocos2d-2.0-x-2.0.3, I get the following warning in CDAudioManager.m:

/libs/CocosDenshion/iphone/CDAudioManager.m:395:11: 'delegate' is deprecated: first deprecated in iOS 6.0

for the piece of code:


  • (id) init: (tAudioManagerMode) mode {
    if ((self = [super init])) {
    //Initialise the audio session
    AVAudioSession* session = [AVAudioSession sharedInstance];
    session.delegate = self;// <——— DEPRECATED IN IOS 6.0

Any suggestions on how to fix this?



I also am having the exact same problem, but in Cocos2D-iPhone. This is how it’s written in the 2.1 template, but it’s throwing the same error, and I can’t find a suitable replacement either.

I thought, “Ok. We’re just trying to set the CDAudioManager as the delegate for this audio session, right?” So I tried:

[session setDelegate:self];

only to find out “setDelegate:” is deprecated in iOS 6 too. Please help!


Ok. I also posted this over on stackoverflow.com. I know this is all Objective-C code and I thought Cocos2D-x was for C++, but anyway, I figured it would still be prudent to post my findings:

I found a poast about this on the Cocos2D-iPhone.org forums. While I don’t fully understand it—but I’m working on it—it did seem to take care of the problem, at least temporarily. What he did was write this method in the CDAudioManger.m file:

@ -(void) releaseBufferForFile:(NSString ) filePath {
int bufferId = ;
if {
freedBufferId = [[NSNumber alloc] initWithInt:bufferId];
[freedBufferId autorelease];
[freedBuffers addObject:freedBufferId];

- (void) interruption:(NSNotification*)notification
    NSDictionary *interuptionDict = notification.userInfo;
    NSUInteger interuptionType = (NSUInteger)[interuptionDict valueForKey:AVAudioSessionInterruptionTypeKey];

    if (interuptionType == AVAudioSessionInterruptionTypeBegan)
        [self beginInterruption];
#if __CC_PLATFORM_IOS >= 40000
    else if (interuptionType == AVAudioSessionInterruptionTypeEnded)
        [self endInterruptionWithFlags:(NSUInteger)[interuptionDict valueForKey:AVAudioSessionInterruptionOptionKey]];
    else if (interuptionType == AVAudioSessionInterruptionTypeEnded)
        [self endInterruption];


Then he replaced:

AVAudioSession *session = [AVAudioSession sharedInstance];
session.delegate = self;

with this:

[AVAudioSession sharedInstance];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(interruption:) name:AVAudioSessionInterruptionNotification object:nil];

Here’s the link: http://www.cocos2d-iphone.org/forum/topic/49956

If and when I develop a better understand of what this code is doing, I’ll be sure to edit this post.


this did not work for me. I had a situation where there were quite a bit of interruptions going on and the interrupts functions where not being called . I had to use this code:
NSUInteger interuptionType = [[interuptionDict valueForKey:AVAudioSessionInterruptionTypeKey] integerValue];

Also may i note a potential bug i found recently only on IOS6 (IOS7 was fine) . When flipping an avcapture cam multiple interruptions can occur messing things up. My solution was to lock CDmanager from resuming til avcam was finished doing its thing then call cdmanager audioSessionResume.