How to get the name of the running application in iOS

前端 未结 10 849
误落风尘
误落风尘 2020-12-25 09:28

If the application name under the icon on the home screen is \"My Awesome App\" how do you get that string within the application at runtime?

相关标签:
10条回答
  • 2020-12-25 10:06

    Just because I love the Xcode 4.5 new way to get an array item. :)

    - (NSString*)project_getAppName {
        return NSBundle.mainBundle.infoDictionary[@"CFBundleDisplayName"];
    }
    
    0 讨论(0)
  • 2020-12-25 10:11

    I’d try

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

    although presumably you know your own app’s name and can just use it…

    0 讨论(0)
  • 2020-12-25 10:11

    Swift 3/4

    let appName =  Bundle.main.object(forInfoDictionaryKey: kCFBundleNameKey as String) as? String
    
    0 讨论(0)
  • 2020-12-25 10:12
    NSString* applicationName = [entry objectForKey:(id)kCGWindowOwnerName];
    

    Here is a good post with examples of what you are looking for. The OP didn't accept anything, which is unfortunate, but the answers are useful.

    0 讨论(0)
提交回复
热议问题