【问题标题】:Loading Custom NSBundle within NSBundle在 NSBundle 中加载自定义 NSBundle
【发布时间】:2023-12-28 15:18:02
【问题描述】:
NSBundle *customBundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"CustomBundle" ofType:@"bundle"]];

当我执行上述代码时,它会在调试模式和 Adhoc Build 中返回 customBundle。但是当我在 TestFlight Build/App Store Build 中使用 32 位设备执行时,它会返回 nil。此外,customBundle 通过 CocoaPods 添加到主包中。我正在使用 Xcode 7.3。

我只在 iOS 9+ 中遇到了这个奇怪的错误,它在 iOS 8 中完美运行。对于 iOS 8,它适用于所有 Build/Adhoc/Appstore 构建,包括所有 32 位和 64 位设备。

【问题讨论】:

    标签: ios objective-c iphone ios9 xcode7


    【解决方案1】:

    我遇到了同样的问题。

    此错误是因为您在 64 位设备上构建捆绑包时,xcode 将密钥 UIRequiredDeviceCapabilities 添加到捆绑包内的 info.plist 中。(捆绑包仅在调试模式下构建,仅适用于活动架构)

    <key>UIRequiredDeviceCapabilities</key>
        <array>
            <string>arm64</string>
        </array>
    

    您可以通过删除 info.plist 中的 UIRequiredDeviceCapabilities 键或使用 32 位设备重建捆绑包并更新 podspec 来解决该错误。

    【讨论】: