gpt4 book ai didi

ios - CFNetwork 内部错误(0xc01a :/BuildRoot/Library/Caches/com. apple.xbs/Sources/CFNetwork_Sim/CFNetwork-808.2.16/Loading/URLConnectionLoader.cpp:304)

转载 作者:行者123 更新时间:2023-11-30 12:29:16 26 4
gpt4 key购买 nike

appName[8121:97068] 8121: CFNetwork internal error (0xc01a:/BuildRoot/Library/Caches/com.apple.xbs/Sources/CFNetwork_Sim/CFNetwork-808.2.16/Loading/URLConnectionLoader.cpp:304)

我有一个聊天应用程序,我想向其他人发送图像。

我:iPhone;其他:模拟器

我用相机拍一张照片,然后按“使用这张照片”,然后我会将网址发送给其他人并将图像上传到服务器。
其他人立即收到 url 消息,而我使用 sdWebimage 来显示此图像。
但是,当我收到图像时,图像请求打印日志错误。
日志说该图像不存在。
不知道是否导致此图片下载错误,图片是否正在上传且服务器没有此图片。
如何防止这种情况或者有什么功能可以设置下载错误10秒后重新下载?

这是我的 sd_image 函数:

 cell.photoImageView.sd_setImage(with: url, placeholderImage: nil, options: .progressiveDownload, progress: nil
, completed: { (image, error, cacheType, url) in

guard image != nil else{
print("Image not exist!")
cell.photoImageView.image = resizeImage(image:#imageLiteral(resourceName: "img_refresh"), newWidth: 125)
return
}

print("image here!!!")

DispatchQueue.global().async {
let data = try? Data(contentsOf: url!) //make sure your image in this url does exist, otherwise unwrap in a if let check / try-catch

if data != nil
{
if let image = UIImage(data: data!)
{
if !FileManager.default.fileExists(atPath: fileURL.path) {
if let jpegData = UIImageJPEGRepresentation(image, 0.001)
{
do {
try jpegData.write(to: fileURL, options: .atomic)
print("image save local done!!!")
} catch {
debug(object: error)
}
}
} else {
print("image already esist")

}

DispatchQueue.main.async {
cell.photoImageView.image = resizeImage(image: image, newWidth: 175)

self.tableView.reloadRows(at: [indexPath], with: .automatic)
}
}
}
}
})

正在上传

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

let uuid = NSUUID().uuidString
let imageName:String = chatroomId + "_" + uuid + ".jpg"
let documentsPath = NSHomeDirectory().appending("/Documents/\(chatroomId)/")
let imagePath = documentsPath.appending(imageName)
let imageUrl = URL(fileURLWithPath: imagePath)
print("imageUrl is here:\(imageUrl)")

photoImage = info[UIImagePickerControllerOriginalImage] as? UIImage


if picker.sourceType == .camera {

photoImage = info[UIImagePickerControllerOriginalImage] as? UIImage
UIImageWriteToSavedPhotosAlbum(photoImage!, nil, nil, nil)
}

let imageData:Data = UIImageJPEGRepresentation(photoImage!, 0.001)!
do {
try imageData.write(to: imageUrl,options: .atomic)
} catch let error {
print(error)
}

//uploading
let objectKey:String = "chatroom/" + imageName
server.uploadObjectAsync(imageUrl, objectKey: objectKey)
let message = server.url + imageName
self.room.send(message: message)
self.tableView.scrollToBottom()
self.tableView.reloadData()
self.dismiss(animated: true, completion: nil)

}

最佳答案

尝试将 .allowInvalidSSLCertificates 添加到您的 sd_setImage 函数中:

cell.photoImageView.sd_setImage(with: url, placeholderImage: nil, options: .allowInvalidSSLCertificates, progress: nil
, completed: { (image, error, cacheType, url) in

关于ios - CFNetwork 内部错误(0xc01a :/BuildRoot/Library/Caches/com. apple.xbs/Sources/CFNetwork_Sim/CFNetwork-808.2.16/Loading/URLConnectionLoader.cpp:304),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43796040/

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