Non-AppKit equivalent for NSWorkspace and/or future-proof poseAsClass?
Non-AppKit equivalent for NSWorkspace and/or future-proof poseAsClass?
- Subject: Non-AppKit equivalent for NSWorkspace and/or future-proof poseAsClass?
- From: Phill Kelley <email@hidden>
- Date: Wed, 9 Jan 2008 23:59:42 +1100
G'Day!
I'm trying to write an application in two parts: a client GUI and a
faceless "agent" (launched by launchd), communicating via Distributed
Objects. This all works.
Among other things, I want the agent to respond to notifications sent by
NSWorkspace (like NSWorkspaceDidLaunchApplicationNotification,
NSWorkspaceDidMountNotification, and friends). This all works too.
The problem occurs when I try to make the the agent a proper agent (ie,
launched by launchd).
The property list has LSBackgroundOnly=1 and LSUIElement=1 (I've also
experimented with LSUIPresentationMode=4).
Early on I found that trying to build the agent without any nibs caused the
thing to barf, so I used a dummy MainMenu.nib. After that, the agent would
launch properly and behave correctly most of the time. But, very
occasionally, it would get into a loop where it would abort during launch,
after which launchd would promptly restart it, repeat, with serious
consumption of CPU cycles until launchd gave up. The console log always had
the same message for each crash:
"Window Server communications from outside of session allowed for
root and console user only"
and the first part of the crash dump always had:
Exception: EXC_BREAKPOINT (0x0006)
Code[0]: 0x00000002
Code[1]: 0x00000000
Thread 0 Crashed:
0 com.apple.Foundation 0x9282845f _NSRaiseError + 227
1 com.apple.Foundation 0x9284f247 +[NSException
raise:format:] + 57
2 com.apple.AppKit 0x9329ea00 +[NSScreen screens] + 191
3 com.apple.AppKit 0x9329e920 +[NSScreen _zeroScreen] + 36
4 com.apple.AppKit 0x9329cfd4 -[NSWindowTemplate
nibInstantiate] + 181
5 com.apple.AppKit 0x93284e30 -[NSIBObjectData
instantiateObject:] + 232
6 com.apple.AppKit 0x93284379 -[NSIBObjectData
nibInstantiateWithOwner:topLevelObjects:] + 202
7 com.apple.AppKit 0x9327b9ad loadNib + 260
8 com.apple.AppKit 0x9327b3d9 +[NSBundle(NSNibLoading)
_loadNibFile:nameTable:withZone:ownerBundle:] + 918
9 com.apple.AppKit 0x9327b03a +[NSBundle(NSNibLoading)
loadNibFile:externalNameTable:withZone:] + 164
10 com.apple.AppKit 0x9327af7c +[NSBundle(NSNibLoading)
loadNibNamed:owner:] + 392
11 com.apple.AppKit 0x9327acc3 NSApplicationMain + 433
12 com.lgosys.TestServer 0x0000212a _start + 216
13 com.lgosys.TestServer 0x00002051 start + 41
I've dealt with this by defining a small private class which includes the
class method:
+(BOOL) loadNibNamed:(NSString*)aNibNamed owner:(id)owner
{
return YES;
}
and then sticking the following at the beginning of main.m:
[[MyClass class] poseAsClass:[NSBundle class]];
That (a) allows me to build without any nibs in the bundle and (b) appears
to cure the crash on launch. All other things being equal, my problem would
seem to be solved. However, I'm not overly happy with this as a solution.
For one thing, poseAsClass is now deprecated so it isn't really a long-term
answer.
The underlying problem, really, is that I'm having to load AppKit just to
get NSWorkspace. That's the *only* thing I need from AppKit.
So, I have two questions:
1. Can I get the same NSWorkspace notifications from somewhere else? I've
nosed through /System/Library/Frameworks without stumbling across anything
obvious but I may just be blind.
2. Does anyone happen to know if there is an equivalent for the poseAsClass
mechanism (or can suggest an alternative approach that will keep AppKit
happy)?
Regards & thanks, PK
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden