0 Replies
      Latest reply on Oct 6, 2019 7:12 PM by anders.u
      anders.u Level 1 Level 1 (10 points)




        I've been trying to introduce usage of AVAssetDownloadStorageManager.setStorageManagementPolicy().

        For some reason the value I set has no effect.


        I set the new policy in the didFinishDownloadingTo delegate method like below, but when I immediately read it back the value hasn't changed.

        Reading it again on re-launch of the app, the value has also not been changed.

        Any advice on what I'm doing wrong is appreciated.


            func urlSession(_ session: URLSession, assetDownloadTask: AVAssetDownloadTask, didFinishDownloadingTo location: URL) {
                guard let delegate = self.delegates.object(forKey: FileCodeKey(assetDownloadTask.fileCode)) else { return }
                if #available(iOS 11, *) {
                    // Set the storage policy for the downloaded content
                    let storageManager = AVAssetDownloadStorageManager.shared()
                    let newPolicy = AVMutableAssetDownloadStorageManagementPolicy()
                    newPolicy.priority = .important
                    newPolicy.expirationDate = Date(timeIntervalSinceNow: 60 * 60 * 24 * 365)
                    storageManager.setStorageManagementPolicy(newPolicy, for: location)
                    if let policy = storageManager.storageManagementPolicy(for: location) {
                        print("After policy.priority: \(policy.priority)")
                        print("policy.expirationDate: \(policy.expirationDate)")