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

时间:2017-05-05 03:31:47

标签: ios swift nsurlconnection alamofire sdwebimage

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;其他:模拟器

我用相机拍照,然后按"使用此照片"然后我会向其他人发送网址并将图片上传到服务器。
其他人立即收到网址留言,我使用sdWebimage来显示此图片。
但是,当我收到图像时,图像请求打印日志错误 记录说这个图像不存在。
我不知道这个图像下载错误,图像是否上传,服务器是否没有这个图像。
如何防止这种情况或有任何功能在下载错误10秒后再次设置下载?

这是我的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)

}

1 个答案:

答案 0 :(得分:0)

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

let subset = TypesAndMembers.WithNameLike("m").ToHashSet()
from i in Issues
where i.CodeElement.IsTypeOrMember &&
       subset.Contains(i.CodeElement)
select new { i, i.Debt, i.Severity }