FairPlay streaming content key persistence
Implementation
We use FairPlay with:The AVContentKeySession API for iOS 11+
The AVAssetResourceLoader API for iOS 10.x
References
We based our implementation on:The official Apple developer documentation
WWDC20 - 10655 - Discover how to download and play HLS offline
Several versions of Apple's HLSCatalog sample project found there
Issues
Everything works fine on most iOS versions, but on iOS 12.x we are facing blocking errors when trying to create SPCs with a valid FairPlay certificate or persisting received CKCs.SPC Creation
AVContentKeySession
The following line causes the error:Code Block swift keyRequest.makeStreamingContentKeyRequestData(forApp: certificate, contentIdentifier: contentIdentifierData, options: [AVContentKeyRequestProtocolVersionsKey: [1]])
AVAssetResourceLoader
The following line causes the error:Code Block swift try loadingRequest.streamingContentKeyRequestData(forApp: certificate, contentIdentifier: contentIdentifierData, options: [AVAssetResourceLoadingRequestStreamingContentKeyRequestRequiresPersistentKey: true])
Error log
Code Block (Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed." UserInfo={NSLocalizedFailureReason=An unknown error occurred (-12158), NSLocalizedDescription=The operation could not be completed., NSUnderlyingError=0x2820a55c0 {Error Domain=NSOSStatusErrorDomain Code=-12158 "(null)"}})
CKC persistence
AVContentKeySession
The following line causes the error:Code Block swift try keyRequest.persistableContentKey(fromKeyVendorResponse: keyData, options: nil)
AVAssetResourceLoader
The following line causes the error:Code Block swift try loadingRequest.persistentContentKey(fromKeyVendorResponse: keyData, options: nil)
Error log
Code Block (Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed." UserInfo={NSLocalizedFailureReason=An unknown error occurred (-12158), NSLocalizedDescription=The operation could not be completed., NSUnderlyingError=0x28104ef40 {Error Domain=NSOSStatusErrorDomain Code=-12158 "(null)"}})
Related issues
Here are different references related to our current issue, that we thought could be of intereset:
What we tried
Implementing a retry mechanism on the failing methods: obviously does not fix the issue, but it works sometimes.
Implementing the AVContentKeySession APIs since we were at first only using AVAssetResourceLoader and its delegate protocol: as said earlier, we are facing now the issues with both APIs.
Removing AVContentKeySession and stop calling asset.resourceLoader.preloadsEligibleContentKeys = true on iOS 12.4+, as suggested in the first Stack Overflow related issue
Thanks in advance,
William