NSBundle dynamic loading problem
NSBundle dynamic loading problem
- Subject: NSBundle dynamic loading problem
- From: "Josh Ferguson" <email@hidden>
- Date: Mon, 19 Dec 2005 12:13:44 -0600
- Thread-topic: NSBundle dynamic loading problem
I have a framework that needs to be loaded dynamically in order to
support self-updating. I'm finding unexplainable behavior and I was
curious if anyone had any input. Here's what's happening:
1.) I create an NSBundle instance of the bundle I want to load
2.) I call -[NSBundle load] to load the executable code (and I get a
notification that the bundle was loaded)
3.) I get the version of the framework and determine the class name to
load based on the frameworks version
4.) I load a class using NSClassFromString() (we'll call it MyClass1, if
the framework is version 1)
5.) The class instance connects to a server and checks for an updated
version. If it's found it downloads it to a temp directory
6.) I move the old framework to the trash, and copy the new framework to
the old location.
7.) I load the new bundle from the temp directory. The new bundle has a
new bundle identifier (com.mycompany.myclass2, for example).
8.) -[NSBundle load] returns YES, but I never get a bundle loaded
notification.
9.) +[NSBundle allFrameworks] shows my framework loaded from the temp
directory and has <loaded> next to it.
10.) I call NSClassFromString() passing it the name of the new class
version (MyClass2) but it fails to get the class. At this point, if I
quit my app and relaunch, it'll load MyClass2 like it's supposed to, so
I know it's not a problem with the framework. At some point, the runtime
is determining that the bundle is already loaded, even though the
framework name, identifier, and principal class are all different.
Calling -[NSBundle principleClass] on the bundle returns a null
class...however, calling +[NSBundle bundleWithIdentifier:], passing it
the new framework's identifier returns the new framework. It's just the
executable code that's not getting loaded.
Here's some pseudo-code:
MakeCallToFramework(NSString *pathToBundle)
{
...
NSBundle *myBundle = [NSBundle bundleWithPath:pathToBundle];
Class MyClass;
If(!myBundle)
Error out;
If(![myBundle load])
Error out;
unsigned long myVersion = GetIntegerVersion([myBundle
objectForInfoDictionaryKey:@"CFBundleVersion"]);
If(!(MyClass = NSClassFromString([NSString
stringWithFormat:@"MyClass%lu", myVersion])))
Error out;
// It's here that I'm failing on the second time around.
The first load always works, regardless of version.
// Between calls to this function, pathToBundle is
modified (I load from a different location the second time around)
...
}
I've been beating my head over this for days...if anyone has any insight
it would be greatly appreciated.
Josh Ferguson
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden