当设备被锁定时,无法访问文档子文件夹中的某些文件。
AVAudioFile(forReading: currentPlaylistURLs[index!])
当设备被锁定或屏幕关闭,并且URL位于Documents文件夹中的某个子文件夹中时,上面的行将抛出一个错误。并非所有子文件夹都会导致错误(为什么??)。当设备被解锁时,没有错误。我在iOS 13.2.3中注意到了这种行为,因此它在此版本之前运行良好。
错误是:
[AVAudioFile.mm:134:AVAudioFileImpl: (ExtAudioFileOpenURL((CFURLRef)fileURL, &_extAudioFile)): error -54
Error Domain=com.apple.coreaudio.avfaudio Code=-54 "(null)" UserInfo={failed call=ExtAudioFileOpenURL((CFURLRef)fileURL, &_extAudioFile)}有人经历过吗?
发布于 2019-11-23 16:18:26
您还需要将文件的文件保护密钥权限设置为.none及其父文件夹:
extension URL {
var parentDirectory: URL? { try? resourceValues(forKeys: [.parentDirectoryURLKey]).parentDirectory }
var fileProtection: URLFileProtection? { try? resourceValues(forKeys: [.fileProtectionKey]).fileProtection }
func disableFileProtection() throws { try (self as NSURL).setResourceValue(URLFileProtection.none, forKey: .fileProtectionKey) }
}let fileURL = URL.init(...)
if let parentDirectory = fileURL.parentDirectory {
do {
try parentDirectory.disableFileProtection()
try fileURL.disableFileProtection()
}
catch { print(error) }
}https://stackoverflow.com/questions/58982719
复制相似问题