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

后端 未结 4 1577
一整个雨季
一整个雨季 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:42

    I haven't tested this but according to this post: http://www.cocos2d-iphone.org/forums/topic/cdaudiomanager-line-402-delegate-is-deprecated/#post-390211

    float osVersion = [[UIDevice currentDevice].systemVersion floatValue];
    if (osVersion >=6.0)
    {
    [AVAudioSession sharedInstance];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(interruption:) name:AVAudioSessionInterruptionNotification object:nil];
    }
    else
    {
    AVAudioSession* session = [AVAudioSession sharedInstance];
    session.delegate = self;
    }
    

    I.e. throw different code runtime depending on iOS version.

    Now, my app is iOS 6.0+ only anyway so I'll just go with:

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

    And cross my thumbs.

提交回复
热议问题