Posts

Post not yet marked as solved
1 Replies
1.3k Views
I have a Swift app that includes On-Demand Resources, I haven't found any official solution to purge/remove ODR programmatically.But I found a workaround to purge the ODR pragmatically bylet request = NSBundleResourceRequest(tags: [resource.tag]) let dispatchGroup = DispatchGroup() dispatchGroup.enter() request.conditionallyBeginAccessingResources { [weak self] resourcesAvailable in defer { dispatchGroup.leave() } guard resourcesAvailable else { return } do { try self?.fileArchiveProvider.removeFile(at: resource.absoluteOriginURL.deleteLastPathComponents(components: 2)) } catch { print(" \(error)") } } dispatchGroup.wait() request.endAccessingResources()The code above works well with the simulator, but it doesn't work with real device. On real device, it throws exception: Error Domain=NSCocoaErrorDomain Code=513 "“com.flashgordon.asset-pack-5d28ed3b881fb0e1f33c7f139b8ea675.assetpack” couldn’t be removed because you don’t have permission to access it." UserInfo={NSUserStringVariant=( Remove ), NSFilePath=/var/mobile/Library/OnDemandResources/AssetPacks/48EE9540-1F9E-415F-BBC9-6EC07DBD1782/7452398430216108346/com.unibet.flashgordon.asset-pack-5d28ed3b881fb0e1f33c7f139b8ea675.assetpack, NSUnderlyingError=0x2800e4270 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}There are also many people asking similar questions:https://stackoverflow.com/questions/48070294/on-demand-resources-force-purge-clear-of-downloaded-resource-bundleshttps://stackoverflow.com/questions/37599767/on-demand-resources-purgingSo my question is: Is there any way to force purge ODR from bundle programmatically? Thanks.
Posted Last updated
.