Get Version Number of iOS Universal Framework in Client

Get version number of iOS Universal Framework in client

I have found that Apple's new Cocoa Touch frameworks supported in Xcode 6, offer an easy answer to this problem. In the default header file created for you, something like Framework.h, you'll see two constants declared for you. These are defined later presumably at runtime by internal framework logic. But I have confirmed they're pulled from the plist for the framework.

//! Project version number for LocalSearch.
FOUNDATION_EXPORT double FrameworkVersionNumber;

//! Project version string for LocalSearch.
FOUNDATION_EXPORT const unsigned char FrameworkVersionString[];

Get Cocoa Touch Framework project version string in Swift

I have actually found a potential workaround for this issue, it's not so clean but it does work:

By default, when Xcode creates a framework it sets the Version to 1.0 and the Build to $(CURRENT_PROJECT_VERSION) which is great, because this value is actually being copied from the Current Project Version field in Build Settings > Versioning.

So what you can do to get this value at runtime is as follows:

let bundle = NSBundle(identifier: "com.yourframework.Framework")! // Get a reference to the bundle from your framework (not the bundle of the app itself!)
let build = bundle.infoDictionary![kCFBundleVersionKey] as! String // Get the build from the framework's bundle as a String

This does work but it feels quite circuitous for something that used to (I believe) be readily accessible from a variable in Objective-C.

IMPORTANT UPDATE - OCT 2021 - XCODE 13

When submitting an app to the App Store, Xcode 13 has a new option called "Manage Version and Build Number" which is ticked by default. If left checked, Xcode will automatically set your app's version number which (rather counter-intuitively), will also apply to all included frameworks. In other words, if your app version is 1.0, your framework version will be overwritten with 1.0.

Make sure you disable this option to avoid your framework version being overwritten.

You can also opt-out of this new behaviour by setting manageAppVersionAndBuildNumber in your export options plist.

For further details, see this discussion on the Apple Developer Forums.

How to get current version of sparkle framework used in MacOS Xcode project

Possibility through code listed here. i.e., read info.plist inside framework. Also you can manually visit Sparkle.framework⁩ ▸ ⁨Versions⁩ ▸ ⁨A⁩ ▸ ⁨Resources⁩⁩ ▸ ⁨Info.plist and can check Bundle version property.

i have a questions when i use iOS-Universal-Framework

you should avoid #define as much as possible

one way is to make a setter/getter function to for it

e.g.

// public header file

void SetCompanyId(int value);
// int GetCompanyId(); // it can be in public header or private header

// some .m or .c or .cpp file

static int companyId;

int GetCompanyId() { return copanyId; }
void SetCompanyId(int value) { companyId = value; }

or if the user mush provide a id, just make it a global variable. you can add const to it so the value can't change

// header file in your framework
extern const int kCompanyId;

// some implementation file in user code
const int kCompanyId = 2;

then user must provided a company id otherwise it will have linker error

How to check version of iOS Branch SDK

Alex from Branch.io here:

You can check the version number in the Info.plist file inside the framework package. Look for these lines:

<key>CFBundleShortVersionString</key>
<string>{version number}</string>

Universal Links have been supported since v0.11. However, even if you have a version with support, you really should be using the latest version at all times since we're constantly adding new functionality and handling for edge cases from Apple and others (there was a new one just this week with iOS 10.2, for example)

Getting Realm Version in Code

If you're embedding Realm Swift as a dynamic framework directly, the version number is contained in the framework's info.plist file. It should be possible to access the plist during runtime; there's a few answers on SO discussing this.

Since CocoaPods creates dynamic frameworks for Swift, the above approach of accessing the info plists should work, but if it doesn't there might be other ways to access versions of pods.

In any case, I would definitely recommend you review why you're wanting to check the version numbers of your libraries. It's better practice to check a framework's capabilities at runtime (eg, testing a class you need exists etc) than to directly use the version number.

For your second question, you need to run pod update RealmSwift to get CocoaPods to check for an updated version of Realm.



Related Topics



Leave a reply



Submit