“仅在使用资源加载捆绑包时找不到CFBundle的可执行文件” >>

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

我正在使用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将本地化文件加载到我的iOS应用中。由于我正在使用Xcode 11进行构建,因此一切仍然可以按预期运行,但是每次我从...

ios objective-c localization nsbundle
1个回答
0
投票

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

如果尚未将捆绑包的可执行代码动态加载到正在运行的程序中,则该代码。

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