gpt4 book ai didi

ios - NSData 在 9.0 版中给我一个错误

转载 作者:搜寻专家 更新时间:2023-10-31 22:19:41 24 4
gpt4 key购买 nike

下面给出了我用 swift 编写的函数这段代码在 10.0 版本的 iPhone 中工作正常但在 9.0 中给出了一个错误 saying

CFURLCopyResourcePropertyForKey failed because it was passed an URL which has no scheme Failed to load: The file “Recording2017-03-06_11.08.53000.mp3” couldn’t be opened.

partFileURL 将具有

/private/var/mobile/Containers/Data/Application/B8F9055D-D816-4E27-BA2A-B13F0EE97709/tmp/Recording2017-03-06_11.08.53000.mp3

这是我的以下功能-:

//function
func putPartUplaod(partFileURL:URL , partFileNumber:Int)
{
var partfileData:Data?
var md5hash:Any?
var sha256hash:Any?
// var error: NSError?
let uri:URL = NSURL(fileURLWithPath: partFileURL.absoluteString) as URL

//Get MD5 Digest
do{
print(partFileURL)
partfileData = try NSData(contentsOf: uri, options: NSData.ReadingOptions.dataReadingMapped) as Data
print("hello" , partfileData);
md5hash = partfileData?.md5().base64EncodedString()
}catch let error as NSError {
print("Failed to load: \(error.localizedDescription)")
}
}

最佳答案

您可以使用类似 NSData *data = [[NSFileManager defaultManager] contentsAtPath:path]; 您传入的字符串不是有效的 URL,它只是一个文件路径。要使其成为 URL,您需要添加 file:// 的方案。

关于ios - NSData 在 9.0 版中给我一个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42618725/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com