In objective C how to determine a library framework version

Posted on 2012-09-12
Medium Priority
Last Modified: 2016-02-10
Is there any method in objective c or NS libraries to retrieve the version number of a framework library?
I want to do it from the code because I have a framework library and some apps that depend on this library.  I usually distribute the framework once but need to update the apps continuously; however, when someone has an issue with an app, I would like to make sure they are using the latest framework library so I want to update my program to display the framework version.
I know that one way would be to add a method to the framework but it's already distributed.
Another way would be to look in their /Library/Frameworks/myframework but I would prefer to use an existing method to get the framework version if possible.
Question by:rudy2024
LVL 33

Accepted Solution

pgnatyuk earned 2000 total points
ID: 38393568
Probably, you link a project with your framework statically, so you can add a macro to your framework like:
(If I understand your question correctly).

In Objective-C you can use respondToSelector method to detect if a method exists in a class and this way is used sometimes to detect programmatically the UIKit version.
For example, only in iOS 5 you can use the appearance feature:
if ([[UINavigationBar class] respondsToSelector:@selector(appearance)]) {
    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"oho.png"] forBarMetrics:UIBarMetricsDefault];

You probably know that you can detect the bundle version:
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];

You can detect the iOS version:
if ([[[UIDevice currentDevice] systemVersion] floatValue] > 5.0) {
More here:
Build Programming Guide
Maybe this way with the bundles will help you.

It is possible ot use a macro:

    NSLog(@"iPhone 4.2");

or __IPHONE_OS_VERSION_MIN_REQUIRED, All of these defines are here:

Read this post about it:
Tips & Tricks for conditional iOS3, iOS3.2 and iOS4 code

Author Closing Comment

ID: 38400021
Thank you for your answer, the links were also very helpful, now I know what to do next time I release a framework update.

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Loops Section Overview

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question