[iOS] Get the name of the running application

Posted in :

滿奇怪的,因為 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’

The following is from Apple’s documentation on Core Foundation Keys

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:

https://stackoverflow.com/questions/8320860/how-to-get-the-name-of-the-running-application-in-ios

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *