Initial persistency set-up
The application must access the OTVPersistenceManager
and set up the listeners; this only has to be done once, before any other persistence operation. Calling OTVPersistenceManager.sharedManager()
for the first time initialises the OTVPersistenceManager
object. The manager can then discover persistent assets stored in previous runs of the application.
Example code
Create or access the download manager
The following code example shows how to gain access to the download manager.
let dlManager = OTVPersistenceManager.sharedManager
Register listeners
To follow the state and progress of downloads, listeners (observers) should be attached with the NotificationCenter
.
NotificationCenter.default.addObserver(self,
selector: #selector(self.storeStateNotification),
name: .OTVAssetDownloadStateChanged,
object: nil)
NotificationCenter.default.addObserver(self,
selector: #selector(self.storeProgressNotification),
name: .OTVAssetDownloadProgress,
object: nil)
@objc func storeStateNotification(notification: NSNotification) {
if let info = notification.userInfo as? [String: Any] {
let state = info[OTVPersistenceAsset.Keys.downloadState] as? String
let name = info[OTVPersistenceAsset.Keys.name] as? String
}
}
@objc func storeProgressNotification(notification: NSNotification) {
if let info = notification.userInfo as? [String: Any] {
let title = info[OTVPersistenceAsset.Keys.name] as? String
let percent = info[OTVPersistenceAsset.Keys.percentDownloaded] as? Double
}
}
Next step:
For clear content, you can start the download.
For FPS encrypted content, you may need to retrieve the licence if the content identifier is known. Otherwise, you need to create an instance of
OTVLicenseDelegate
and set it toOTVPersistenceManager
to start the download.