如何判断 AirPlay 是否正在镜像?

How to tell if AirPlay is mirroring?

我正在开发具有 AirPlay 功能的视频内容应用程序。当它通过 AirPlay (AVPlayer) 流式传输视频内容时,设备上的 UI 将是播放器的遥控器,但是当 AirPlay 设置为镜像时,它会按预期在两个设备上显示相同的界面,因为我只知道连接了AirPlay,但我不知道它是否是镜像。我使用以下代码检查 AirPlay 连接:

- (BOOL)isAirPlayTVOutput {
    return ([self isAirplayActive] && ![self isBluetoothOutputType]);
}

- (BOOL)isAirplayActive {
    self.deviceOutputType = nil;
    self.airplayDeviceName = nil;

    AVAudioSessionRouteDescription *routeDescription = [[AVAudioSession sharedInstance] currentRoute];
    for (AVAudioSessionPortDescription *portDescription in routeDescription.outputs) {
        self.deviceOutputType = portDescription.portType;
        self.airplayDeviceName = portDescription.portName;

        if ([portDescription.portType isEqualToString:AVAudioSessionPortAirPlay]) {
            return YES;
        }
    }

    return NO;
}

我怎么知道它是不是镜像?

我可以使用这个答案中的解决方案来解决这个问题:

不是最好的解决方案,但可能是唯一可用的。