ios - 仅加载包含资源的 bundle 时出现 "Cannot find executable for CFBundle"

标签 ios objective-c localization nsbundle

我正在使用 NSBundle 将本地化文件加载到我的 iOS 应用程序中。

由于我使用 Xcode 11 进行构建,一切仍然按预期工作,但每次我从该包中读取本地化内容时都会收到警告:

Cannot find executable for CFBundle [...] (not loaded)

问题是 bundle 中没有可执行文件。它只包含本地化文件和一个 Info.plist ,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>$(DEVELOPMENT_LANGUAGE)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>$(PRODUCT_NAME)</string>
    <key>CFBundlePackageType</key>
    <string>BNDL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>NSPrincipalClass</key>
    <string></string>
</dict>
</plist>

bundle 已加载

NSBundle *bundle = [NSBundle bundleWithPath:path];
if (![bundle isLoaded]) {
    [bundle load];
}

和本地化阅读

NSString *string = [bundle localizedStringForKey:key value:defaultValue table:nil];

最佳答案

显然 - load from NSBundle 仅用于从包中加载可执行文件。 来自 documentation :

Dynamically loads the bundle’s executable code into a running program, if the code has not already been loaded.

对于仅包含资源的 bundle ,无需调用 - load

关于ios - 仅加载包含资源的 bundle 时出现 "Cannot find executable for CFBundle",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59732224/

相关文章:

ios - 在 iOS 中使用 Flurry Analytics 结束 session

objective-c - 是否可以在 cocoa xib/nib 中嵌入终端窗口?

javascript - Fabric js 自定义旋转图标仅在 iphone 的 google chrome 浏览器中不可见

android - 如何获取从网站远程触发的移动用户的 GPS 位置

objective-c - C 或 Obj-c 函数将范围标准化为 x-y

android - 更改语言环境后更改通知栏中的字符串

python - 如何在 Python 中将货币字符串转换为 float ?

ios - 简单的CoreGraphics绘图偶尔会崩溃,但仅在iOS 7上会崩溃

ios - 找出何时触发无限的每日重复UILocalnotification

Gitlab 上的 Java 字符编码差异