2011-09-17 55 views
1

的CFBundleIdentifier我有哪裏不[[NSBundle mainBundle] infoDictionary]只包含這一個案例:可可/ ObjC:獲取當前進程

17.09.11 18:28:26,936 [0x0-0x5a98a93].com.valvesoftware.steam: 2011-09-17 18:28:26.935 steam[85587:707] infodict: { 
17.09.11 18:28:26,936 [0x0-0x5a98a93].com.valvesoftware.steam:  CFBundleExecutablePath = "/Applications/Spiele/Steam.app/Contents/MacOS/osx32/steam"; 
17.09.11 18:28:26,936 [0x0-0x5a98a93].com.valvesoftware.steam:  NSBundleInitialPath = "/Applications/Spiele/Steam.app/Contents/MacOS/osx32"; 
17.09.11 18:28:26,936 [0x0-0x5a98a93].com.valvesoftware.steam:  NSBundleResolvedPath = "/Applications/Spiele/Steam.app/Contents/MacOS/osx32"; 
17.09.11 18:28:26,936 [0x0-0x5a98a93].com.valvesoftware.steam: } 

但我想要得到的CFBundleIdentifier。

是否有另一種(更一般的)方法來獲取當前進程的CFBundleIdentifier?

回答

3

[[NSRunningApplication runningApplicationWithProcessIdentifier:getpid()] bundleIdentifier]的作品。

+0

你總是比我好:) – Yuji

+0

'[[NSBundle mainBundle] bundleIdentifier]'工作嗎?這將是最簡單的解決方案... – MrMage

+0

@MrMage:不,返回'nil'。 – Albert

0
NSString *CFBundleIdentifier = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"]; 


(CFBundleIdentifier = @"com.yourcompany.yourapp")