在iOS应用程序中检测AirPlay镜像



我有一个用XCode内置的iOS应用程序,主要针对iPad的Objective C。

基本上,我想在我的应用程序内部检测AirPlay镜像是否处于活动状态,所以主要是设备是否镜像到另一个屏幕。

我在堆栈溢出周围搜索了所有内容,但我找不到我需要的东西。一些答案说我必须为此使用UIScreenDidConnectNotification

问题是,如果镜像处于活动状态或镜像被激活时,以及镜像停止时,我必须调用一个函数。所以我认为我需要一个侦听器来进行镜像更改。

你能帮帮我吗?

我对iOS开发相对较新,所以如果我可能不知道所有的事情,请不要生气:)

我找到的一些答案:

  • https://stackoverflow.com/a/30319663/2866662
  • https://stackoverflow.com/a/22321926/2866662
  • https://stackoverflow.com/a/9027616/2866662
  • https://stackoverflow.com/a/10576262/2866662

谢谢!

下面介绍了如何通过订阅通知来调用任何函数,您可以在viewDidLoad或您认为必要时执行此操作:

[[NSNotificationCenter defaultCenter] addObserver:self
        selector:@selector(receiveAirPlayNotification:) 
        name: UIScreenDidConnectNotification
        object:nil];

并接收它:

- (void) receiveAirPlayNotification:(NSNotification *) notification
{
  //Do whatever you want here, or call another function
  NSLog(@"Received Notification - %@", notification); 
  [self doMyThing];
}

最新更新