Cocos2D 2.1: “Delegate” deprecated in iOS 6. How do I set the delegate for this AVAudioSession?

后端 未结 4 1610
一整个雨季
一整个雨季 2021-02-05 19:17

Started a Cocos2D 2.1 template (with no physics engine) in Xcode 4.5, targeted for iOS 6 and iPad. In the CDAudioManager.m file, the following code...

AVAudioSe         


        
4条回答
  •  没有蜡笔的小新
    2021-02-05 19:46

    Instead of using delegate use notification for handling as follows

    [AVAudioSession sharedInstance];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(interruption:) name:AVAudioSessionInterruptionNotification object:nil];
    
     - (void) interruption:(NSNotification*)notification
       {
        NSDictionary *interuptionDict = notification.userInfo;
    
        NSUInteger interuptionType = (NSUInteger)[interuptionDict valueForKey:AVAudioSessionInterruptionTypeKey];
    
       if (interuptionType == AVAudioSessionInterruptionTypeBegan)
            [self beginInterruption];
    
        else if (interuptionType == AVAudioSessionInterruptionTypeEnded)
            [self endInterruption];
    }
    

提交回复
热议问题