Cocos2D 2.1:“代理”在iOS 6中已弃用。如何设置此AVAudioSession的代理?
在Xcode 4.5中启动Cocos2D 2.1模板(没有物理引擎),针对iOS 6和iPad。在CDAudioManager.m文件中,以下代码...
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...
AVAudioSession* session = [AVAudioSession sharedInstance];
session.delegate = self; // Which is what is automatically generated by the template.
...生成以下警告...
...generates the following warning...
"delegate deprecated: first deprecated in iOS 6"
所以我去苹果开发者文档,它在委托下面说,在iOS 6.0中已经不推荐使用这个类的通知部分所述的通知。
So I go to the apple developer documentation, and it says under "delegate," "Deprecated in iOS 6.0. Use the notifications described in the Notifications section of this class instead."
问题是,看起来像我们正在努力的一切 - 原谅我的缺乏经验 - 将AVAudioSession的代理设置为CDAudioManager实例本身。通知如何完成这个?或者我只是错误的上述代码的目标?
Problem is, it looks to me like all we're trying to do--forgive my inexperience--is set the delegate for the AVAudioSession to the CDAudioManager instance itself. How do the notifications accomplish this? Or am I just wrong about the goal of the above code?
您正在运行的错误是在这个代码块
The error you are running into is in this block of code
AVAudioSession* session = [AVAudioSession sharedInstance];
session.delegate = self;// <-------- DEPRECATED IN IOS 6.0
为了使警告更改为静音,请将这两行改为:
To silence the warning change those 2 lines to this:
[[AVAudioSession sharedInstance] setActive:YES error:nil];
希望这有帮助。