Manual FairPlay License Renewal: AVContentKeySessionDelegate not triggering via addContentKeyRecipient

Hi everyone,

I am working on an app that supports offline playback with FairPlay Streaming (FPS). I have successfully implemented the logic to download and persist the content keys (TLLV), and offline playback is working correctly using the stored persistent keys.

However, I am now trying to implement a manual renewal process for these licenses, and I’ve run into an issue where the delegate methods are not being fired as expected.

The Issue: I am calling contentKeySession.addContentKeyRecipient(asset) to force a renewal or re-fetch of the content key for a specific asset. Even though the asset is correctly initialized and the session is active, the AVContentKeySessionDelegate methods (specifically contentKeySession(_:didProvide:)) are not being triggered at all.

My Questions:

Why is the delegate not firing when adding the recipient? Is there a specific state or property the AVURLAsset needs to have (or a specific way it should be initialized) to trigger a new key request via addContentKeyRecipient?

Is it possible to perform a manual license renewal triggered by a UI action (e.g., a button tap) without actually initiating playback of the asset?

The goal is to allow users to refresh their licenses manually while online, ensuring the content remains playable offline before the previous license expires, all without forcing the user to start the video.

Any insights or best practices for this manual renewal flow would be greatly appreciated.

Hello,

Let me first clarify the use of contentKeySession.addContentKeyRecipient. This method is used to map the recipient (e.g. AVURLAsset) to the session such that any keys necessary for that recipient are handled by the given session.

contentKeySession.addContentKeyRecipient does not initiate a key load.

The only way to load a key is via processContentKeyRequest(withIdentifier:initializationData:options:) or via the AVPlayer which will invoke the delegate callbacks with the AVContentKeyRequest.

Regarding renewal, please take a look at renewExpiringResponseData(for:) to initiate a key renewal. You should then expect the contentKeySession(_:didProvideRenewingContentKeyRequest:) callback to be fired which will have a new content key request for an existing content key.

You mentioned renewing keys specific to the AVURLAsset. There is a property on the AVContentKeyRequest called originatingRecipient which maps the request to the recipient (AVURLAsset here). You can use this property to renew requests specific to the asset.

Hope that helps!

Hi @SumayyaS , thanks for the response!

I've updated my code to use processContentKeyRequest, but the delegate doesn't fire unless I also initialize an AVPlayer.

When I call processContentKeyRequest alone with the identifier, nothing happens. However, as soon as I create an AVPlayerItem and AVPlayer with the asset, the delegate triggers immediately.

Am I missing a step to trigger the request manually without an AVPlayer? I’d appreciate any further insights!

Here is my code:

func renewLicense(for asset: AVURLAsset) {
    // get identifier from asset URL
    let identifier = asset.url.pathComponents[3]
    
    isRenew = true
    contentKeySession.addContentKeyRecipient(asset)
    contentKeySession.processContentKeyRequest(withIdentifier: identifier, initializationData: nil)
    
    let item = AVPlayerItem(asset: asset)
    let _ = AVPlayer(playerItem: item)
  }

@ithans Could you file a ticket with Feedback Assistant - https://developer.apple.com/feedback-assistant/ describing this issue? Please include a sample app with the AVContentKeySession implementation and a sysdiagnose so I can further investigate with more context.

To create the sysdiagnose, make sure you install the CoreMedia logging profile. Instructions found here - https://developer.apple.com/services-account/download?path=/iOS/iOS_Logs/CoreMedia_Logging_Instructions.pdf

Once you create the ticket, paste the FB Assistant ID here and I can track the bug internally. Thanks!

Manual FairPlay License Renewal: AVContentKeySessionDelegate not triggering via addContentKeyRecipient
 
 
Q