CFNETWORK内部错误(0xc01a:/buildroot/library/caches/com.apple.xbs


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)

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

i:iPhone;其他:模拟器

我通过相机拍摄照片,然后按"使用此照片",然后将URL发送给其他人并将图像上传到服务器。
其他人立即收到URL消息,我使用sdwebimage显示此图像。
但是,当我收到图像时,图像请求打印日志错误。
日志说此图像不存在。
我不知道让此图像下载错误,是否上传和服务器没有此图像。
如何防止这种情况或有任何功能在下载错误后再次设置下载?

这是我的sd_image func:

 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)
}

尝试添加.allailInvalidsslcertificates totifificate to sd_setimage函数:

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

最新更新