如何仅在swift中的委托(继承)中指定可用性?

时间:2015-10-22 09:22:28

标签: ios swift cocoa-touch

我的应用程序将在iOS 9之后支持AVPlayer中的PIP,但我仍然想让我的应用程序在iOS 7及更高版本中运行。关于可用性检查,我阅读了this post。但它似乎不适合我的情况。例如:

我的代码:

class PlayerViewController: UIViewController, AVPictureInPictureControllerDelegate

这在iOS 9中运行良好,但如何使其在iOS 7及更高版本中运行?我不能这样做:

   @available(iOS 9.0, *)
   class PlayerViewController: UIViewController, AVPictureInPictureControllerDelegate
   @available(iOS 7.0, *)
   class PlayerViewController: UIViewController

有什么建议吗?感谢。

1 个答案:

答案 0 :(得分:3)

将代理代码分解为扩展名:

class PlayerViewController: UIViewController {
}
@available(iOS 9.0, *)
extension PlayerViewController: AVPictureInPictureControllerDelegate {
}