This piece of code is crashing on iOS 12 with unrecognised selector exception:
[AVPlayerItem externalMetadata]: unrecognized selector sent to instance
However, this code is not crashing on iOS 13.
Apple documentation states that AVPlayerItem has externalMetadata getter and setter since iOS 12.
let item = AVPlayerItem(url: videoURL)
let mutableMetadataItem = AVMutableMetadataItem()
mutableMetadataItem.identifier = AVMetadataIdentifier.commonIdentifierDescription
mutableMetadataItem.value = 1
item.externalMetadata.append(mutableMetadataItem)
Could you please help me to understand why is that happening?
externalMetadatawas introduced in iOS 13. That fact is explicitly called out in the relevant WWDC 2019 video. Simply put, the docs (or the availability tags) are wrong — and the result of the mistake is that you are permitted to useexternalMetadatain a context (iOS 12) where it is actually absent, and so you crash.