Problem with NSWorkspaceDidMountNotification
Problem with NSWorkspaceDidMountNotification
- Subject: Problem with NSWorkspaceDidMountNotification
- From: Glenn Zelniker <email@hidden>
- Date: Mon, 9 May 2005 17:28:56 -0400
I'm writing an application that reads data from a set of DVDs or CDs.
While the app is running, the user can attempt to load a piece of data
from one of the discs. The app detects whether or not the disc is
mounted and, if not, prompts the user to insert the required disc. At
this point, I would like to make use of NSWorkspace's notifications,
specifically NSWorkspaceDidMountNotification, and then check to see if
the disc is among the workspace's mountedRemovableMedia.
I have verified that the notifications work as expected. That is, I can
indeed receive the desired notification and I can check the volume name
to see if it's the one I want. But I'm having a problem making it work
properly within the method in which I want it to work. If I register
for the notification in my controller's -awakeFromNib method, I can get
the notification while the application is idling. But when I try to
wait for notification within a loop that looks like this:
###############
mounted = NO;
while (!mounted)
{
-- wait, do other stuff --
}
###############
it doesn't work. For completeness, I register for the notification like
this:
###############
[[NSWorkspace notificationCenter] addObserver:self
selector:@selector(discMounted:)
name:NSWorkspaceDidMountNotification
object:nil];
###############
and when the notification is posted, the following is supposed to get
called:
###############
- (void)discMounted:(NSNotification *)sender
{
-- check to see if it's the right volume --
mounted = YES;
}
###############
Because I can get it to work properly when I'm NOT in a loop as above,
I'm guessing that the problem has to do with the notification center
not wanting to post notifications while I'm in a different run loop.
I've tried registering for the notification from within and near the
loop, but this still doesn't work. In fact, if I skip the notification
entirely and simply keep checking the workspace for
mountedRemovableMedia, I still don't see the disc when it's inserted in
the drive as long as I'm in a loop checking for it.
I'm in something of a catch-22. I can't proceed until I see the disc,
but I can't see the disc until I proceed. I've even tried detaching a
new thread that looks for the disc, to no avail. Any suggestions?
Glenn Zelniker
_______________________________________________
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