繁体   English   中英

使用 SDWebImageSVGCoder 下载 SVGImage 时应用程序崩溃

[英]Application crashed while downloading SVGImage using SDWebImageSVGCoder

我在我的项目中使用来自 API 的 SVG 图像,因为我知道没有直接的方法来使用、加载或下载 SVG 图像直接到 iOS Swift 应用程序所以我使用第三方库 SDWebImageSVGCoder。 但我面临两个问题,第一个应用程序在下载特定图像时崩溃,第二个是在 Objective-C 中编写的。我在 Objective-C 中表现不佳,所以我尝试了很多来了解这个问题,我也尝试了其他一些库,但它们也没有帮助。 我需要帮助,因为我被困在那里,应用程序每次都崩溃,我不知道。 谢谢

这是我的代码

import SDWebImageSVGCoder

@main
class AppDelegate: UIResponder, UIApplicationDelegate {



    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        let SVGCoder = SDImageSVGCoder.shared
        SDImageCodersManager.shared.addCoder(SVGCoder)
        return true
    }
}
import UIKit
import SDWebImageSVGCoder

struct Bank:Decodable {
    var icon: String?
    var name: String?
}

class ViewController: UIViewController {
    
    var banks: [Bank] = [Bank(icon: "https://identity.moneyhub.co.uk/bank-icons/virgin", name: "Virgin Money")]
    @IBOutlet weak var tableView: UITableView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupTableView()
    }
    
    func setupTableView() {
        self.tableView.delegate = self
        self.tableView.dataSource = self
    }


}

//MARK: - TABLEVIEW DELEGATE DATASOURCE
extension ViewController: UITableViewDelegate, UITableViewDataSource {
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return banks.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: BankTableViewCell.identifier, for: indexPath) as! BankTableViewCell
        cell.configure(self.banks[indexPath.row])
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 62
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
    }
    
}


class BankTableViewCell: UITableViewCell {
    
    @IBOutlet weak var bankNameLabel: UILabel!
    @IBOutlet weak var bankLogoImageView: UIImageView!
    
    class var identifier: String {
        return "BankTableViewCell"
    }
    
    func configure(_ bank: Bank) {
        self.bankNameLabel.text = bank.name
        guard let url = URL(string: bank.icon ?? "") else {return}
        bankLogoImageView.sd_imageIndicator = SDWebImageActivityIndicator.gray
        bankLogoImageView.sd_setImage(with: url)
    }
    
}

我想知道为什么这个库崩溃了我在 pod Github 上发布了问题,但他们没有回应。 请给我任何我可以使用并解决我的问题的建议、解决方案或替代库。 谢谢

您正在使用不再受支持的过时库。 要解决崩溃问题,您需要使用 SDWebImageSVGNativeCoder。 可以在这里下载: https://github.com/SDWebImage/SDWebImageSVGNativeCoder

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM