How to display IPFS images in Swift

Viewed 316

I am trying to display IPFS image in swift using UIImageView . When I run my code in xCode/Simulator the image shows fine. . When I run my code in Xcode/My iPhone device connected via USB works. I do see the image

But when run the app on my phone (after app is installed via Xcode) the IPFS image is not shows for the UIImageView - what am I doing wrong?

func tableView(_ myTableViewAccount: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell: TableViewCellAccount = myTableViewAccount.dequeueReusableCell(withIdentifier: "aCell") as! TableViewCellAccount
        guard (self.accountsArray.count > 0) else { return cell }
        
        print("accountArray=\(self.accountsArray)  indexPath=\(indexPath.row)")
        let count = self.accountsArray.count
        if (indexPath.row < count) {
            guard (self.accountsArray[indexPath.row].name != nil) else { return cell }
            cell.accountImgView?.frame.size = CGSize(width: 50, height: 50)
            cell.accountImgView.center = view.center
            cell.accountImgView.layer.cornerRadius = 18
            cell.accountImgView?.clipsToBounds = true
            
            let activityIndicator = UIActivityIndicatorView()
            activityIndicator.frame = cell.accountImgView.bounds
            cell.accountImgView.addSubview(activityIndicator)
            activityIndicator.backgroundColor = UIColor.white
            activityIndicator.startAnimating()
          
            let front_img_url = "https://cloudflare-ipfs.com/ipfs/QmYFDgVBMrRfEm5JpVSWeSDAfTUpboEiL8rZyGym24MNVu"
            let frontImageURL = URL(string: front_img_url)
            if frontImageURL != nil {
                DispatchQueue.main.async {
                    let dataProdFrontImg = try? Data(contentsOf: frontImageURL!)

                    if let data_front_img = dataProdFrontImg {  //fromn img
                        activityIndicator.stopAnimating()
                        activityIndicator.removeFromSuperview()
                        
                        let accountImage = UIImage(data: data_front_img)
                        cell.accountImgView.image = accountImage
                    }
                }
            }
        }
        return cell
    }

... Cell Table is defined like this

class TableViewCellAccount: UITableViewCell {
    
    @IBOutlet weak var accountImgView: UIImageView!
    
    override func awakeFromNib() {
        super.awakeFromNib()
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
    }
}
1 Answers

I moved away from UIImage View instead, I used

 @IBOutlet weak var accountImgView: WKWebView?

that fixed my issue

Related