5

I'm writing an iOS SDK using Objective-C programming language. I would like to know if there is a field in Xcode where i can set version number for SDK

Is there a way in objective-C to set version and build number the way we do it for iOS apps (EX: Version: 2.5.1 Build: 2.5.1.12) ?

Also need a way to detect this version number so i can expose an API something like

- (NSString *)getSDKVersion {
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    NSString *majorVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    NSString *minorVersion = [infoDictionary objectForKey:@"CFBundleVersion"];

    return [NSString stringWithFormat:@"SDK Version %@ (%@)", majorVersion, minorVersion];
}

-(NSString*)getSDKBuildVersion;

Which returns the SDK version and build number.

Using: Xcode - 7.0 (Beta 3 version)

Thanks in advance.

Ankit Jain
  • 1,858
  • 22
  • 35
  • 1
    If your SDK has a Info.plist file you can put your version in `CFBundleShortVersionString` key and your build number in `CFBundleVersion`. To retrieve them : `[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]` or `[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]` – ryancrunchi Jul 21 '15 at 12:42
  • @ryancrunchi updated the question with the implementation. On executing the above API i'm getting null response. – Ankit Jain Jul 21 '15 at 12:48
  • 1
    You may have to create your own bundle (a SDK's bundle) and access it with `[NSBundle bundleWithIdentifier:@"id"]...`. From apple's doc : `This method is typically used by frameworks and plug-ins to locate their own bundle at runtime ` – ryancrunchi Jul 21 '15 at 12:52

1 Answers1

3

You can set version and build number clicking in the Project(left side) -> General tab(right side) -> Identity section. You will find the fields: Bundle Identifier, Version and Build.

For get the values programmatically:

NSDictionary *infoDictionary = [[NSBundle mainBundle]infoDictionary];

NSString *version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
NSString *build = [infoDictionary objectForKey:kCFBundleVersionKey];
Wesley Galindo
  • 936
  • 7
  • 8
  • 1
    Thank you but when we create SDK project General tab will not be there. And i have edited the info.Plist file still i'm unable to get the version number using the 'CFBundleShortVersionString" key. – Ankit Jain Jul 22 '15 at 04:46
  • @AnkitJain Can you find solution to set custom sdk version? – Vipulk617 Nov 05 '17 at 06:17
  • To make this work in my framework, I had to replace `[NSBundle mainBundle]` with `[NSBundle bundleForClass:self.class]`. – Eric Lange Jul 30 '18 at 08:26