A fix for AudioSessionInitialize Deprecated?

前端 未结 5 1072
半阙折子戏
半阙折子戏 2021-02-05 07:31

Apple did not post any alternative code for this on the Apple Developer site.

5条回答
  •  不思量自难忘°
    2021-02-05 08:20

    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)
        {
        }
    }
    

提交回复
热议问题