ios 如何获得捆绑ID?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8873203/
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-08-30 16:19:42  来源:igfitidea点击:

How to get bundle ID?

iosnsbundle

提问by jln646v

I am working on getting the facebook API working for iOS, and the FB registration page requires the Bundle ID of the project. How can I get this information? I read something about getting it at run time, but is there a way to get Xcode to tell me this information, or is it held in a plist somewhere. I am not using the default bundle id, I remember setting it while I created the project.

我正在努力让 facebook API 适用于 iOS,而 FB 注册页面需要项目的 Bundle ID。我怎样才能得到这些信息?我读了一些关于在运行时获取它的内容,但是有没有办法让 Xcode 告诉我这些信息,或者它是否保存在某个 plist 中。我没有使用默认的 bundle id,我记得我在创建项目时设置了它。

回答by Aks

If you are trying to get it programmatically , you can use below line of code :

如果您尝试以编程方式获取它,则可以使用以下代码行:

objective C

目标C

NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];

Swift 3.0 :

斯威夫特 3.0:

let bundleIdentifier =  Bundle.main.bundleIdentifier

It will work for both iOS and Mac apps Good luck..

它适用于 iOS 和 Mac 应用程序祝你好运..

回答by plátano plomo

For those using Xcode >=7: select your target and click the Generaltab. Bundle Identifieris found under Identity.

对于使用 Xcode >=7 的用户:选择您的目标并单击“常规”选项卡。捆绑标识符位于Identity下。

回答by Nikso

In Xcode 4, select your project, then your target (you should have only one) and then the 'Info' tab. You should be able to see the bundle identifier there.

在 Xcode 4 中,选择您的项目,然后选择您的目标(您应该只有一个),然后选择“信息”选项卡。您应该能够在那里看到包标识符。

回答by Avijit Nagare

You can find out and change from supporting file=> info.plist => Bundle identifier

您可以从支持文件=> info.plist => Bundle identifier 中找出并更改

It is generally DNS form ex. com.companyname.appname

它通常是 DNS 形式的 ex。com.companyname.appname

enter image description here

在此处输入图片说明

回答by James Turner

If you're build a library, this may be problematic - it's applications that have a bundle ID. However, your can probably query this programatically using [NSBundle mainBundle]and then [NSBundle bundleIdentifier]

如果您正在构建一个库,这可能会出现问题 - 它是具有捆绑 ID 的应用程序。但是,您可能可以使用[NSBundle mainBundle]然后以编程方式查询[NSBundle bundleIdentifier]

回答by Vasily Bodnarchuk

Details

细节

  • Xcode 11.2.1 (11B500), Swift 5.1
  • Xcode 11.2.1 (11B500),Swift 5.1

Programmatically

以编程方式

Solution 1

解决方案1

let bundleId = Bundle.main.bundleIdentifier

Solution 2

解决方案2

let bundleId = Bundle.main.infoDictionary?["CFBundleIdentifier"] as? String


From Xcode

来自 Xcode

Solution 1

解决方案1

enter image description here

在此处输入图片说明

Solution 2

解决方案2

enter image description here

在此处输入图片说明

回答by yoAlex5

A bundle IDor bundle identifier identifies an application in Apple's ecosystem. Apple advice to use reverse domain name(reverse DNS notation) to create it.

bundle ID或束标识符标识在苹果的生态系统的应用程序。Apple 建议使用反向域名(反向 DNS 表示法)来创建它。

For example:

例如:

com.companyname

Bundle identifier is a string in Info.plist[About]which is required for any Bundle

捆绑标识符是Info.plist[About] 中的一个字符串,对于任何Bundle

To setit using Xcode

设置其使用的Xcode

//Info.plist
Bundle identifier
//by default it points on `$(PRODUCT_BUNDLE_IDENTIFIER)` which is you can setup in Build Settings

//Build Settings the mirror of Target Settings
Build Settings -> Product Bundle Identifier

//Target Settings the mirror of Build Settings
General -> Bundle Identifier

To getit programmatically

以编程方式获取

//Objective-C
[[NSBundle mainBundle] bundleIdentifier];

//Swift
Bundle.main.bundleIdentifier

[Vocabulary]

[词汇]