• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSBundle dynamic loading problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: NSBundle dynamic loading problem
      • From: Shaun Wexler <email@hidden>
    • Re: NSBundle dynamic loading problem
      • From: Uli Kusterer <email@hidden>
  • Prev by Date: creating a nsview without IB
  • Next by Date: [CORE DATA] BackgroundFetching app explanation, and more...
  • Previous by thread: Re: creating a nsview without IB
  • Next by thread: Re: NSBundle dynamic loading problem
  • Index(es):
    • Date
    • Thread