在成功进行应用内购买后,我一直在尝试访问下载的SKDownload
zip 文件:
func paymentQueue(_ queue: SKPaymentQueue, updatedDownloads downloads: [SKDownload]) {
downloads.forEach ({ (download) -> Void in
switch download.state {
...
case .finished:
self.processDownload(download: download)
...
break
...
})
}
这是处理下载SKDownload
文件的函数:
func procesessDownload(download: SKDownload) {
guard let hostedContentPath = download.contentURL else {
return
}
do {
// THIS LINE OF CODE THROWS WITH THE ERROR POSTED BELOW
let files = try FileManager.default.contentsOfDirectory(atPath: hostedContentPath.relativePath)
} catch {
//catch error
}
}
当我检查download.contentURL
它时:
file:///private/var/mobile/Containers/Data/Application/D755EC3C-2BA6-43A8-BB21-938B38EBFCB7/Library/Caches/EB11461D-71C8-42C7-9C99-E6F8B81161EE.zip/
- _url : file:///private/var/mobile/Containers/Data/Application/D755EC3C-2BA6-43A8-BB21-938B38EBFCB7/Library/Caches/EB11461D-71C8-42C7-9C99-E6F8B81161EE.zip/
但是在尝试FileManager
使用上面的这行代码访问文件时:
let files = try FileManager.default.contentsOfDirectory(atPath: hostedContentPath.relativePath)
我不断收到以下错误消息,指出该文件不存在:
Error Domain=NSCocoaErrorDomain Code=260 "The file “EB11461D-71C8-42C7-9C99-E6F8B81161EE.zip” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/private/var/mobile/Containers/Data/Application/D755EC3C-2BA6-43A8-BB21-938B38EBFCB7/Library/Caches/EB11461D-71C8-42C7-9C99-E6F8B81161EE.zip, NSUnderlyingError=0x28320d500 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
我尝试
/
在最后添加以将 zip 文件视为目录和许多其他内容均无济于事。我什至尝试访问包含该文件的目录(直到 zip 文件):
/private/var/mobile/Containers/Data/Application/D755EC3C-2BA6-43A8-BB21-938B38EBFCB7/Library/Caches/
错误说找不到“缓存”目录。
- 我还尝试
"Contents"
像随机人找到的示例代码之一一样添加到路径中。
我已经连续敲了一天多的头,但找不到任何关于此事的文件。任何帮助将不胜感激,谢谢!