                     
                     guard let dataRequest = resourceLoadingRequest.dataRequest else {
                         print("no data is being requested in loadingRequest")
-                        let error = NSError(domain: AssetLoaderDelegate.errorDomain, code: -6, userInfo: nil)
+                        let error = NSError(domain: AssetLoaderDelegate.errorDomain, code: -5, userInfo: nil)
                         resourceLoadingRequest.finishLoading(with: error)
                         return
                     }
                     
                     // Provide data to the loading request.
+                    saveCurrentTimeForContentKey()
                     dataRequest.respond(with: persistentContentKeyData)
                     resourceLoadingRequest.finishLoading()  // Treat the processing of the request as complete.
                     

             using the information we obtained earlier.
             */
            spcData = try resourceLoadingRequest.streamingContentKeyRequestData(forApp: applicationCertificate, contentIdentifier: assetIDData, options: resourceLoadingRequestOptions)
        } catch let error as NSError {
            print("Error obtaining key request data: \(error.domain) reason: \(String(describing: error.localizedFailureReason))")
            resourceLoadingRequest.finishLoading(with: error)
            return
        }

        } catch {
            print("An error occured removing the persisted content key: \(error)")
        }
    }
    
    public func saveCurrentTimeForContentKey() {
        UserDefaults.standard.set(Date(), forKey: "\(assetName)-Key-Time")
    }
    
    public func clearCurrentTimeForContentKey() {
         UserDefaults.standard.removeObject(forKey: "\(assetName)-Key-Time")
    }
    
    public func isContentKeyExpired() -> Bool {
        
        guard let date = UserDefaults.standard.object(forKey: "\(assetName)-Key-Time") as? Date else {
            return true
        }
        
        let interval = Double(date.timeIntervalSinceNow) * -1
        
        guard (interval / 60)  <= AssetLoaderDelegate.licenseExpirationTimeInMinute else {
            return true
        }
        
        return false
    }
    
}
