AudioSessionInitialize

AudioSessionInitialize

本文介绍了AudioSessionInitialize的修复已弃用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apple没有在Apple开发者网站上发布任何替代代码。

解决方案

您应该使用AVAudioSession。 p>

要替换由已弃用的AudioSessionInitialize提供的功能(例如,如果您需要指定AudioSessionInterruptionListener回调),您可以订阅AVAudioSessionInterruptionNotification通知:

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

并实现您的audioSessionDidChangeInterruptionType:handler like:

   - (void)audioSessionDidChangeInterruptionType:(NSNotification *)notification 
{
AVAudioSessionInterruptionType interruptionType = [[[notification userInfo]
objectForKey:AVAudioSessionInterruptionTypeKey] unsignedIntegerValue] ;
if(AVAudioSessionInterruptionTypeBegan == interruptionType)
{
}
else if(AVAudioSessionInterruptionTypeEnded == interruptionType)
{
}
}


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

这篇关于AudioSessionInitialize的修复已弃用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-20 11:58