Offline FairPlay Streaming on iOS: Unable to create SPC and persist CKC

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:

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:
  1. Stack Overflow - Fairplay stops working on iOS 12.4 and 13

  2. Stack Overflow - Error while fetching Server Playback Context when downloading Fairplay enabled videos

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

Does anyone encounter the same issues ? Is there a working solution or a stable workaround ?

Thanks in advance,

William
When you get undocumented AVFoundation error codes like this, I recommend that you file a bug report, so that the engineering team can take a look at what's gone wrong. Please post your bug number here for reference.
Hi Polyphonic,

I actually already filed a report on Feedback Assistant with the reference FB8936794.
Any solutions or insight into this error?
Offline FairPlay Streaming on iOS: Unable to create SPC and persist CKC
 
 
Q