Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Launch Services and CFBundleVersion
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Launch Services and CFBundleVersion



On Jun 7, 2006, at 2:12 PM, Rosyna wrote:

Ack, at 6/7/06, Dave Dribin said:

From some investigation, it seems Launch Services does not strictly interpret CFBundleVersion as a NumVersion struct. In fact, some of Apple's own apps violate the "nn.n.nxnnn" format, such as Mail.app, which has an CFBundleVersion of "746.2".

Many of Apple's applications violate this in which case CFBundleGetVersionNumber() returns 0 (radr://4577471). It's best not to do what Apple does and actually follow the documentation.

I found that I couldn't get the version number for iMovie 4.0.1. When I looked at its CFBundleVersion key, I found that the corresponding value was "4.0.1 (3H10)" instead of "4.0.1", so CFBundleGetVersionNumber was failing and returning zero. (Later releases are better behaved.)


Since I have to do a few things differently based on iMovie version, I ended up writing a routine to be a bit more rigorous in getting a valid version number. It doesn't handle really big major version numbers like Mail's 746.2 (which really is version 2.0.7, according to Mail's About box), but iMovie's version numbers are more in line with NumVersion, so this works for my case. If you need a bigger range, modify away...

steve


UInt32 GetIMovieVersion()
{
UInt32 iMovieVersion = CFBundleGetVersionNumber (CFBundleGetMainBundle());


if (iMovieVersion == 0)
{
CFStringRef versionCFString = reinterpret_cast<CFStringRef>(
CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(),
kCFBundleVersionKey));


if ((versionCFString != NULL) && (CFGetTypeID (versionCFString) == CFStringGetTypeID()))
{
char versionString[256];


if (CFStringGetCString(versionCFString, versionString, sizeof(versionString), kCFStringEncodingMacRoman))
{
UInt32 majorVersion, minorVersion, bugVersion = 0;


if ((sscanf(versionString, "%lu.%lu.%lu", &majorVersion, &minorVersion, &bugVersion) == 3) ||
(sscanf(versionString, "%lu.%lu", &majorVersion, &minorVersion) == 2))
{
iMovieVersion = ((majorVersion & 0xff) << 24) |
((minorVersion & 0x0f) << 20) |
((bugVersion & 0x0f) << 16);
}
}
}
}


    return iMovieVersion;
}

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Launch Services and CFBundleVersion (From: Dave Dribin <email@hidden>)
 >Re: Launch Services and CFBundleVersion (From: Rosyna <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.