gpt4 book ai didi

ios - 使用 beginReceivingRemoteControlEvents

转载 作者:技术小花猫 更新时间:2023-10-29 11:22:19 25 4
gpt4 key购买 nike

我看到人们在管理 Audio Session 时使用:[[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; 来处理远程控制事件。

我的问题:

此代码是否只能在 UIViewController 类或 AppDelegate 类中使用?因为我看到互联网上的每个人都在两个类(class)之一中使用它。我可以在不是 UIViewController 或 AppDelegate 子类的类中使用它吗?

最佳答案

对于只想在特定状态下处理远程控制事件的应用程序——例如,准备好播放媒体,而不是在设置或注册屏幕上——调用 beginReceivingRemoteControlEvents View Controller 具有一定的意义。其他应用可能希望完全抑制远程控制行为(因为它们接管了 Audio Session 并且不希望用户触发背景音频并破坏 session 数据)。

但是,没有什么可以阻止您将该行为纳入应用的另一个区域,尤其是在共享的情况下。 beginReceivingRemoteControlEventsUIApplication 上的一个方法,因此只要您能够获得 [UIApplication sharedApplication] 的句柄,您就可以标记应用程序开始/结束远程控制事件处理。

但是,值得注意的是该方法已被弃用:

In iOS 7.1 and later, use the shared MPRemoteCommandCenter object to register for remote control events. You do not need to call this method when using the shared command center object. [1]

此时我在远程控制事件处理方面的经验已经有几年了,但我记得在处理 beginReceivingRemoteControlEvents 时有一些非直观的行为。快速浏览 MPRemoteCommandCenter使这看起来像是一个更好的用于处理远程控制事件的 API。如果您的用例不需要 iOS 7.0 支持,您应该研究该 API。

关于ios - 使用 beginReceivingRemoteControlEvents,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38777250/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com