"Cannot find executable for CFBundle" 仅加载资源包
"Cannot find executable for CFBundle" while loading bundle with resources only
我正在使用 NSBundle
将本地化文件加载到我的 iOS 应用程序中。
因为我是用 Xcode 11 构建的,所以一切仍然按预期工作,但每次我从该包中读取本地化时都会收到警告:
Cannot find executable for CFBundle [...] (not loaded)
问题是捆绑包中没有可执行文件。它只包含本地化文件和一个如下所示的 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>
捆绑包加载
NSBundle *bundle = [NSBundle bundleWithPath:path];
if (![bundle isLoaded]) {
[bundle load];
}
和本地化阅读
NSString *string = [bundle localizedStringForKey:key value:defaultValue table:nil];
显然 NSBundle
中的 - load
仅用于从包中加载可执行文件。
来自 documentation:
Dynamically loads the bundle’s executable code into a running program, if the code has not already been loaded.
对于只有资源的包,没有必要调用 - load
。
我正在使用 NSBundle
将本地化文件加载到我的 iOS 应用程序中。
因为我是用 Xcode 11 构建的,所以一切仍然按预期工作,但每次我从该包中读取本地化时都会收到警告:
Cannot find executable for CFBundle [...] (not loaded)
问题是捆绑包中没有可执行文件。它只包含本地化文件和一个如下所示的 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>
捆绑包加载
NSBundle *bundle = [NSBundle bundleWithPath:path];
if (![bundle isLoaded]) {
[bundle load];
}
和本地化阅读
NSString *string = [bundle localizedStringForKey:key value:defaultValue table:nil];
显然 NSBundle
中的 - load
仅用于从包中加载可执行文件。
来自 documentation:
Dynamically loads the bundle’s executable code into a running program, if the code has not already been loaded.
对于只有资源的包,没有必要调用 - load
。