For anyone having this problem, who is not helped by this post, you may find the following use-full: Here.
Here is a copy of the error:
2018-08-29 18:39:59.458950-0400 proj[5319:3378682] NSURLConnection finished with error - code -1002
I have looked through these answer and not found anything to work. I believe its because the problem is happening for another reason for those. I am having the problem when fetching images from a database and trying to display them in on a image view.
Full code bellow:
import UIKit
import FirebaseStorage
import FirebaseDatabase
import FirebaseAuth
import Firebase
class PhaseOneViewController: UIViewController {
@IBOutlet weak var p1ImageView: UIImageView!
@IBAction func loadImages(_ sender: Any) {
//p1ImageView.image = nil
NKPlaceholderImage(image: UIImage(named: "placeholder"), imageView: p1ImageView, imgUrl: "\(Storage.storage().reference().child((Auth.auth().currentUser?.uid)!).child("post\(takePicViewController().finalPost + PhotoArray.sharedInstance.numberPost)").child(ImageUploadManager().imageName))") { (image) in }
}
func NKPlaceholderImage(image:UIImage?, imageView:UIImageView?,imgUrl:String,compate:@escaping (UIImage?) -> Void) {
if image != nil && imageView != nil {
imageView!.image = image!
}
var urlcatch = imgUrl.replacingOccurrences(of: "/", with: "#")
let documentpath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
urlcatch = documentpath + "/" + "\(urlcatch)"
let image = UIImage(contentsOfFile:urlcatch)
if image != nil && imageView != nil
{
imageView!.image = image!
compate(image)
}else{
if let url = URL(string: imgUrl){
DispatchQueue.global(qos: .background).async {
() -> Void in
let imgdata = NSData(contentsOf: url)
DispatchQueue.main.async {
() -> Void in
imgdata?.write(toFile: urlcatch, atomically: true)
let image = UIImage(contentsOfFile:urlcatch)
compate(image)
if image != nil {
if imageView != nil {
imageView!.image = image!
}
}
}
}
}
}
}
}
I have also asked These questions Link, Link, which may be of help to someone in my situation or to solve this problem.
Thanks!