【问题标题】:Bundle asset retrieval broken when app is loaded from Testflight从 Testflight 加载应用程序时捆绑资产检索中断
【发布时间】: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


    【解决方案1】:

    我发现这个问题有完全相同的问题:

    Pod install has required target membership unchecked

    问题是,捆绑包与模块具有相同的名称。将包名称更改为其他名称可以解决问题,请在此处查看我的答案:https://stackoverflow.com/a/70986055/4755172

    【讨论】:

      猜你喜欢
      • 2020-05-12
      • 1970-01-01
      • 2020-04-19
      • 1970-01-01
      • 2018-03-22
      • 1970-01-01
      • 1970-01-01
      • 2020-11-29
      • 1970-01-01
      相关资源
      最近更新 更多