Get version number of iOS Universal Framework in client

Ryan Poolos picture Ryan Poolos · Jul 2, 2014 · Viewed 13.9k times · Source

This is likely not limited to iOS Universal Frameworks but all xxx.framework files. However I can't seem to find documentation on how to get the current version and build of a framework within the client application. Within an app you'd use something like:

    NSString *name = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];
    NSString *build = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
    NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];

That would give you the current information stored in the Info.plist for the app. But how to we find that information for a framework. And in my case, specifically an embedded framework.

Answer

picciano picture picciano · Mar 23, 2017

Here's a solution that does work with Universal Frameworks. Just replace SomeFrameworkClass with a class from the desired framework.

if let sdkVersion = Bundle(for: SomeFrameworkClass.self).infoDictionary?["CFBundleShortVersionString"] {
    // sdkVersion is available here
}