xcode 使用 CFBundleName 的地方

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12146750/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:21:10  来源:igfitidea点击:

Where CFBundleName is being used

iphoneobjective-ciosxcodecocoa

提问by Ryan

From this old question: What's the difference between "bundle display name" and "bundle name" in cocoa application's info plist

从这个老问题:可可应用程序的信息 plist 中的“捆绑显示名称”和“捆绑名称”之间有什么区别

It points to the official docs, which say:

它指向官方文档,其中说:

CFBundleName

CFBundleName(String - iOS, OS X) identifies the short name of the bundle. This name should be less than 16 characters long and be suitable for displaying in the menu bar and the app's Info window. You can include this key in the InfoPlist.strings file of an appropriate .lproj subdirectory to provide localized values for it. If you localize this key, you should also include the key “CFBundleDisplayName.”

CFB包名

CFBundleName(String - iOS, OS X) 标识包的短名称。此名称应少于 16 个字符,适合显示在菜单栏和应用程序的信息窗口中。您可以将此键包含在相应 .lproj 子目录的 InfoPlist.strings 文件中,以为其提供本地化值。如果您本地化此键,则还应包含键“CFBundleDisplayName”。

Can anyone tell how to show this name in iOS?

谁能告诉如何在iOS中显示这个名字?

I was never able to show this value in my iPhone.

我从来没有能够在我的 iPhone 中显示这个值。

回答by Nate

It doesn't look to me like CFBundleNameshows anywhereto the user, on iOS. I believe I've seen documentation for Mac OS X (which obviously iOS inherits a lot of legacy infrastructure from), that says that the Bundle Name isused for something else ... I think it might have been the name in the upper Menu bar, or the lower Dock bar. Neither thing exists in iOS, of course.

在我看来,它不像在 iOS 上向用户CFBundleName展示的任何地方。我相信我已经看到了为Mac OS X(这显然继承的iOS很多从传统基础设施的),指出该软件包名称的文件用于别的东西...我认为这可能是在上层菜单中的名称栏,或下方的 Dock 栏。当然,iOS 中不存在任何东西。

I also found this Stack Overflow answer, which is now quite old (but with quite a few upvotes). This answer claims that CFBundleName would be the name of the folder that the app is stored in. So, for example, CFBundleName = HelloWorldshould produce

我还发现了这个 Stack Overflow 的答案,它现在已经很老了(但有很多赞成票)。这个答案声称 CFBundleName 将是存储应用程序的文件夹的名称。因此,例如,CFBundleName = HelloWorld应该产生

+- HelloWorld.app
    - HelloWorldApplication

If the Executable Namewas set to be HelloWorldApplication. However, I just built a simple program and ran it on iOS 5.0, and the .app folder was notnamed equal to CFBundleName. So, if it everworked that way, it doesn't seem to any more.

如果可执行文件名称设置为HelloWorldApplication. 但是,我只是构建了一个简单的程序并在 iOS 5.0 上运行它,并且 .app 文件夹的名称等于CFBundleName. 所以,如果它曾经以这种方式工作过,它似乎不再如此。

I have seen quite a few references that say that CFBundleNameshould be left set to ${PRODUCT_NAME}in Xcode, which is what I always do. Not as a technicallimitation, but as an Apple review criterion, I've also seen people claim that CFBundleDisplayNamemust be closely relatedto CFBundleName. For example, it's ok if it's a shortened version of CFBundleName, but that they might reject the app if it's unrelated altogether.

我已经看到很多参考资料说CFBundleName应该${PRODUCT_NAME}在 Xcode 中设置为,这就是我经常做的。不是作为一个技术的限制,但作为苹果审核标准,我也看到了人声称,CFBundleDisplayName必须密切相关CFBundleName。例如,CFBundleName如果它是 .

I also checked the listing in Settings.app, and in iTunes, and I didn't see the Bundle Nameeither of those places.

我还检查了Settings.app和 iTunes 中的列表,但在这两个地方都没有看到Bundle Name

So, to answer your question, I don't believe this variable is visible to the user (on iOS).

所以,为了回答你的问题,我不相信这个变量对用户是可见的(在 iOS 上)。



Update:I have not, however, checked whether or not any accessibility features might speakthis name anywhere.

更新:但是,我没有检查是否有任何辅助功能可以在任何地方使用这个名称。

Also, this SO answerclaims that CFBundleNamewill be the name used in the iTunes App Store URL for your app. But, see @tc.'s comment/example URL below ...

此外,此 SO answer声称这CFBundleName将是您的应用程序的 iTunes App Store URL 中使用的名称。但是,请参阅下面的@tc. 的评论/示例 URL ...



Update 2: per @honus's comment below, one unusualscenario where CFBundleNamecanbe shown to the user is if your app has noentry for CFBundleDisplayNamein its Info.plist file. In that case, CFBundleNamewill be shown under the app icon in SpringBoard.

更新 2:根据下面@honus 的评论,可以向用户显示的一种不寻常情况是您的应用程序在其 Info.plist 文件中没有条目。在这种情况下,将显示在 SpringBoard 的应用程序图标下。CFBundleNameCFBundleDisplayNameCFBundleName

回答by ohr

You can access those keys like this.

您可以像这样访问这些密钥。

[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]

Where infoDicitonaryis A dictionary, constructed from the bundle's Info.plist file. There you can find this sort of information about your App. NSBundle

哪里infoDicitonaryA dictionary, constructed from the bundle's Info.plist file。在那里您可以找到有关您的应用程序的此类信息。NSBundle

Note: You can check the actual key by opening the App-info.plistfile and right clicking anywhere then selecting the option Show Raw Keys/Values.

注意:您可以通过打开App-info.plist文件并右键单击任意位置然后选择选项来检查实际密钥Show Raw Keys/Values

回答by Bernd

CFBundleName IS used, when localizing a MacOS Cocoa App, in the Mac OS MenuBar as the Application Name (right from the File Menu). So it DEFINITELY has a meaning. Don't know, if it is used and shown somewhere else. But better not leave it out, when localizing your app!

CFBundleName 在本地化 MacOS Cocoa 应用程序时,在 Mac OS 菜单栏中用作应用程序名称(直接从文件菜单)。所以它绝对是有意义的。不知道,如果它被使用并显示在其他地方。但在本地化您的应用程序时最好不要忽略它!

回答by Bachsau

On macOS it is used as a means to decide if the application's name should be localized in the Finder. If the actual name of the bundle (of course extended by '.app') matches CFBundleName, Finder will show its localized display name instead. However, a user might rename the App to something he finds more appropriate and in that case, macOS needs a way to tell if the name was customized.

在 macOS 上,它用作决定是否应在 Finder 中本地化应用程序名称的一种方式。如果包的实际名称(当然由“.app”扩展)匹配CFBundleName,Finder 将显示其本地化的显示名称。但是,用户可能会将应用重命名为他认为更合适的名称,在这种情况下,macOS 需要一种方法来判断名称是否是自定义的。

回答by Matt Long

If you open your info.plist file by context clicking it in the project tree and selecting "Open As > Source Code", you'll see the XML representation of the plist. By default, these two keys have the same value, so you could access either one.

如果您通过上下文在项目树中单击它并选择“打开为 > 源代码”来打开 info.plist 文件,您将看到 plist 的 XML 表示。默认情况下,这两个键具有相同的值,因此您可以访问任何一个。

<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>

To actually grab the values, you can use this SO post as a guideline: How to display the current project version of my App to the user?Just replace the CFBundleVersionkey with CFBundleDisplayName.

要实际获取值,您可以使用此 SO 帖子作为指导:如何向用户显示我的应用程序的当前项目版本?只需将CFBundleVersion密钥替换为CFBundleDisplayName.

In essence:

在本质上:

NSString *displayName = [[[NSBundle mainBundle] infoDictionary] 
                                          valueForKey:@"CFBundleDisplayName"];

回答by deleted_user

Bundle name is the name of the actual application bundle on the file system.

包名称是文件系统上实际应用程序包的名称。

Bundle display name is the caption of the application icon that the user will see on either their iOS device or the caption of the icon on OSX.

捆绑显示名称是用户将在其 iOS 设备上看到的应用程序图标的标题或 OSX 上的图标标题。