Kingfisher 最新版本 支持Swift5,但pod要求iOS10以上,
為了支持swfit5, pod 導(dǎo)入的時(shí) 要求最低使用 iOS 10 的系統(tǒng),作者給出理由是iOS10以下的用戶太少,找不到任何理由去支持。太任性了 哈哈!相信依舊給一部分iOS 開發(fā)造成一定的困擾。所以我找到以下方案解決既支持swift5又支持iOS10以下的系統(tǒng),就是本地導(dǎo)入源碼,不通過pod形式。
1.首先先創(chuàng)建一個(gè)新的工程,通過pod 把最新的版本的Kingfisher下載下來,從Pods 文件夾 找到源碼,然后將源碼拖到一個(gè)新的工程中。
2.把源碼進(jìn)行以下的修改,然后運(yùn)行即可。
// MemoryStorage.swfit 75行
cleanTimer = .scheduledTimer(withTimeInterval: config.cleanInterval, repeats: true) { [weak self] _ in
guard let self = self else { return }
self.removeExpired()
}
// 替換如下:
cleanTimer = Timer.init(timeInterval: config.cleanInterval, target: self, selector: #selector(removeExpiredFunc), userInfo: nil, repeats: true)
cleanTimer?.fire()
并且在該類添加一個(gè)方法
@objc func removeExpiredFunc() {
self.removeExpired()
}
// ImageModifier.swift 里面 96行
return image.imageFlippedForRightToLeftLayoutDirection()
// 替換如下:
if #available(iOS 9.0, *) {
return image.imageFlippedForRightToLeftLayoutDirection()
} else {
return image
}
// ImageView+Kingfisher.swift 343行
view.centerXAnchor.constraint(
equalTo: base.centerXAnchor, constant: newIndicator.centerOffset.x).isActive = true
view.centerYAnchor.constraint(
equalTo: base.centerYAnchor, constant: newIndicator.centerOffset.y).isActive = true
// 替換如下:
if #available(iOS 9.0, *) {
view.centerXAnchor.constraint(
equalTo: base.centerXAnchor, constant: newIndicator.centerOffset.x).isActive = true
view.centerYAnchor.constraint(
equalTo: base.centerYAnchor, constant: newIndicator.centerOffset.y).isActive = true
} else {
// Fallback on earlier versions
NSLayoutConstraint.activate([
NSLayoutConstraint(item: self, attribute: .centerX, relatedBy: .equal, toItem: base, attribute: .centerX, multiplier: 1, constant: newIndicator.centerOffset.x),
NSLayoutConstraint(item: self, attribute: .centerY, relatedBy: .equal, toItem: base, attribute: .centerY, multiplier: 1, constant: newIndicator.centerOffset.y),
])
}
// Placeholder.swift 66行
centerXAnchor.constraint(equalTo: imageView.centerXAnchor).isActive = true
centerYAnchor.constraint(equalTo: imageView.centerYAnchor).isActive = true
heightAnchor.constraint(equalTo: imageView.heightAnchor).isActive = true
widthAnchor.constraint(equalTo: imageView.widthAnchor).isActive = true
// 替換入下:
if #available(iOS 9.0, *) {
centerXAnchor.constraint(equalTo: imageView.centerXAnchor).isActive = true
centerYAnchor.constraint(equalTo: imageView.centerYAnchor).isActive = true
heightAnchor.constraint(equalTo: imageView.heightAnchor).isActive = true
widthAnchor.constraint(equalTo: imageView.widthAnchor).isActive = true
} else {
// Fallback on earlier versions
NSLayoutConstraint.activate([
NSLayoutConstraint(item: self, attribute: .centerX, relatedBy: .equal, toItem: imageView, attribute: .centerX, multiplier: 1, constant: 0),
NSLayoutConstraint(item: self, attribute: .centerY, relatedBy: .equal, toItem: imageView, attribute: .centerY, multiplier: 1, constant: 0),
NSLayoutConstraint(item: self, attribute: .height, relatedBy: .equal, toItem: imageView, attribute: .height, multiplier: 1, constant: 0),
NSLayoutConstraint(item: self, attribute: .width, relatedBy: .equal, toItem: imageView, attribute: .width, multiplier: 1, constant: 0)
])
}
// AnimatableImageView.swift 289行
if displayLink.preferredFramesPerSecond == 0 {
duration = displayLink.duration
} else {
// Some devices (like iPad Pro 10.5) will have a different FPS.
duration = 1.0 / Double(displayLink.preferredFramesPerSecond)
}
// 替換如下:
if #available(iOS 10.0, *) {
if displayLink.preferredFramesPerSecond == 0 {
duration = displayLink.duration
} else {
// Some devices (like iPad Pro 10.5) will have a different FPS.
duration = 1.0 / Double(displayLink.preferredFramesPerSecond)
}
} else {
duration = displayLink.duration
}
PS:然后運(yùn)行即可,有問題歡迎留言。