1. 程式人生 > >[iOS] Get the name of the running application

[iOS] Get the name of the running application

滿奇怪的,因為 App Name 的欄位沒輸入,我用CFBundleDisplayName 拿到的值是空的。CFBundleName的值就是正確的。

Ans:

[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];

Swift 3

Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String ?? ""
Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName"
) as? String ?? ""

Swift 2.2

NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleName")
NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleDisplayName")

More about ‘CFBundleName’ and ‘CFBundleDisplayName’

CFBundleName 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…

CFBundleDisplayName specifies the display name of the bundle…

*The app I am working with only has an entry for CFBundleName.

from: