| Article: |
Plug It In, Plug It In | |
| Subject: | deployment candidate fix but didn't work | |
| Date: | 2002-10-22 10:25:54 | |
| From: | psheldon | |
|
Response to: Plug-ins don't load if not running from ProjectBuilder
|
||
|
I went reading PB Help and found I could make a deployment as opposed to a development build style only from the command line interface.
|
||
Showing messages 1 through 2 of 2.
-
deployment candidate fix but didn't work
2003-05-29 09:19:01 anonymous2 [View]
-
Plug-ins don't load if not running from ProjectBuilder
2002-12-27 05:14:16 anonymous2 [View]
The reason plug-ins load when running from ProjectBuilder but not when running the app directly is because it doesn't work in ProjectBuilder either. At least not as you expect.
The problem is this call in discoverPlugins:
NSBundle *plugin = [NSBundle bundleWithPath: name];
You're trying to load a bundle from a path but you only supply a file name. In this case you're looking for "GrayscaleFilter.plugin". Where does NSBundle look for that file? In the current working directory which ProjectBuilder conveniently set to the build directory. If you look in the build directory you'll see GrayscaleFilter.plugin, ImageApp.app, and intermediate files. So NSBundle finds the file and loads it. But it loads the _wrong_ version of GrayscaleFilter.plugin. It doesn't load the one that's inside ImageApp in the PlugIns folder!
The simplest way to fix this is to load the bundle with a full path and not just the file name. So replace the line above by these:
NSString *pluginPath = [path stringByAppendingPathComponent:name];
NSBundle *plugin = [NSBundle bundleWithPath: pluginPath];
I though NSRunAlertPanel() was extremely useful when debugging an application outside of ProjectBuilder.



The problem is caused by a small bug in the code:
we get the plugin by:
plugin = [NSBundle bundleWithPath: name];
and we go the name by enumerate the objetc returned by:
[[NSFileManager defaultManager] directoryContentsAtPath: path]
You will find that the name variable only contains the name of the bundle, but not the path. So the application has to find the bundle in the default directory. And apparently, the envionment setting of running within PB and as a standalone application is different, so it makes our application behave differently.
The solution is add a statement on the first of second while block:
name = [path stringByAppendingPathComponent: name];
You will find that it works fine now.
Good luck.