【发布时间】:2022-02-04 20:03:07
【问题描述】:
我遇到了一个关于我的 iOS SDK 以及在从 Testflight 下载应用程序时它如何检索和显示图像(来自捆绑资产)的问题。
SDK 可以通过 SPM、Cocoapods 和 Carthage 进行集成。这个问题是关于 Cocoapods 集成的。
在本地,即使作为发布版本并在设备上运行时,一切都运行良好,并且正在显示图像:
使用“发布”构建配置在本地构建时,图标会显示。当完全相同的应用程序被归档然后通过 Testflight 下载时,所有图标都消失了。
这就是我从包中检索图像的方式:
let background = UIImage(named: "select_chevrons", in: .current, compatibleWith: nil)?.withRenderingMode(.alwaysTemplate)
因为我以 3 种方式分发我的 SDK(Swift 包、cocoapods 和 carthage),所以我必须实现一个 BundleFinder,它定义了 .current:
import Foundation
private class BundleFinder {}
extension Foundation.Bundle {
/// Returns the resource bundle associated with the current Swift module.
var moduleName = "NAME_OF_MY_SDK"
static var current: Bundle = {
#if SWIFT_PACKAGE
let bundleName = "\(moduleName)_\(moduleName)"
#else
let bundleName = moduleName
#endif
let candidates = [
// Bundle should be present here when the package is linked into an App.
Bundle.main.resourceURL,
// Bundle should be present here when the package is linked into a framework.
Bundle(for: BundleFinder.self).resourceURL,
// For command-line tools.
Bundle.main.bundleURL,
]
for candidate in candidates {
let bundlePath = candidate?.appendingPathComponent(bundleName + ".bundle")
if let bundle = bundlePath.flatMap(Bundle.init(url:)) {
return bundle
}
}
print("unable to find bundle named \(bundleName)")
return Bundle(for: BundleFinder.self)
}()
}
问题:为什么应用来自 Testflight 时图片不显示?如何在本地重现此行为?
【问题讨论】:
标签: ios swift cocoapods swift-package-manager carthage