在实际代码中获取Xcode Project的名称

MrH*_*hma 2 iphone xcode objective-c ipad

所以你知道项目的一部分是"MyNameGoesHere.app"或"MyNameGoesHere.xcodeproj" - 有没有办法通过objective-c代码获取MyNameGoesHere部分?

我可以从UIDevice消息中获取所有类型的设备信息,但我无法弄清楚如何获取项目/应用程序名称.

der*_*iuk 6

CFBundleDisplayName不再起作用了.使用:

NSString *bundleName = [[NSBundle mainBundle]
                         objectForInfoDictionaryKey:@"CFBundleName"];
Run Code Online (Sandbox Code Playgroud)


XCo*_*ool 5

您可能正在查看捆绑包的InfoDictionary.您可以通过以下代码获取应用程序的名称:

NSDictionary *info = [[NSBundle mainBundle] infoDictionary];
NSString *bundleName = [NSString stringWithFormat:@"%@", [info objectForKey:@"CFBundleDisplayName"]];
Run Code Online (Sandbox Code Playgroud)

  • 返回@(null) (2认同)