diff --git a/Sources/WalletConnectRelay/BundleFinder.swift b/Sources/WalletConnectRelay/BundleFinder.swift new file mode 100644 index 000000000..8cf44cbb6 --- /dev/null +++ b/Sources/WalletConnectRelay/BundleFinder.swift @@ -0,0 +1,29 @@ +import class Foundation.Bundle + +private class BundleFinder {} + +extension Foundation.Bundle { + /// Returns the resource bundle associated with the current Swift module. + static var resourceBundle: Bundle = { + let bundleName = "WalletConnect_WalletConnectRelay" + + 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 + } + } + fatalError("unable to find bundle named WalletConnect_WalletConnectRelay") + }() +} diff --git a/Sources/WalletConnectRelay/EnvironmentInfo.swift b/Sources/WalletConnectRelay/EnvironmentInfo.swift index 8e381e520..59947745e 100644 --- a/Sources/WalletConnectRelay/EnvironmentInfo.swift +++ b/Sources/WalletConnectRelay/EnvironmentInfo.swift @@ -18,7 +18,7 @@ enum EnvironmentInfo { } static var packageVersion: String { - let configURL = Bundle.module.url(forResource: "PackageConfig", withExtension: "json")! + let configURL = Bundle.resourceBundle.url(forResource: "PackageConfig", withExtension: "json")! let jsonData = try! Data(contentsOf: configURL) let config = try! JSONDecoder().decode(PackageConfig.self, from: jsonData) return config.version diff --git a/WalletConnectSwiftV2.podspec b/WalletConnectSwiftV2.podspec index 061d1e83f..256509ece 100644 --- a/WalletConnectSwiftV2.podspec +++ b/WalletConnectSwiftV2.podspec @@ -118,6 +118,11 @@ Pod::Spec.new do |spec| spec.subspec 'WalletConnectRelay' do |ss| ss.source_files = 'Sources/WalletConnectRelay/**/*' ss.dependency 'WalletConnectSwiftV2/WalletConnectKMS' + ss.resource_bundles = { + 'WalletConnect_WalletConnectRelay' => [ + 'Sources/WalletConnectRelay/PackageConfig.json' + ] + } end spec.subspec 'WalletConnectUtils' do |ss|