CocoaPod-获取Javascript文件的捆绑包路径

问题描述 投票:0回答:1

[我正在为iOS-Swift创建一个Pod,我试图获取Javascript文件的捆绑包路径(在Development Pods / Router / ModelFetch.js中添加,并且以下代码返回空。

guard let fetchingScript = Bundle.main.path(forResource: "ModelFetch", ofType: "js")

我同意Pod的应用程序捆绑包和捆绑包路径不同,但是如何获取该路径?

ios swift cocoapods bundle podspec
1个回答
0
投票

从分发包中获取资源取决于您用于应用程序依赖项的链接类型。这是我在Framework中使用的方法,您可以将其用于静态和动态链接:

if let bundlePath = Bundle.main.path(forResource: "ModelFetch", ofType: "js") {
    // static framework
} else if let bundlePath = Bundle(for: BundleToken.self).path(forResource: "ModelFetch", ofType: "js") {
    // dynamic framework
}

...

/// Helper class for Bundle search
public class BundleToken {}

您可以使用Framework中的某些类代替BundleToken类。

© www.soinside.com 2019 - 2024. All rights reserved.