Re: Unexpected NSWorkspaceDidMountNotification
Re: Unexpected NSWorkspaceDidMountNotification
- Subject: Re: Unexpected NSWorkspaceDidMountNotification
- From: Ken Thomases <email@hidden>
- Date: Fri, 26 Jun 2009 21:29:09 -0500
On Jun 26, 2009, at 1:45 PM, Buddy Kurz wrote:
Does anyone have any idea why an application would receive a
NSWorkspaceDidMountNotification notification for a volume that was
already mounted when the application started?
I believe this is intentional. I could swear I read about it in the
past, but I can't find the documentation saying so, now. I did find
this, which applies to Carbon, but has the same implication:
http://developer.apple.com/carbon/tipsandtricks.html#MountedVolumes
NSWorkspace, like Carbon, is also depending on notifications from the
DiskArbitration framework, and I believe it notifies all clients of
all volumes at the time they (the clients) connect. Such events are
dispatched from the run loop. If you register to observe the
notification before the run loop has its first chance to run, then
you'll receive notifications for all volumes, including those already
mounted. You have to code with that in mind.
The physical drive is partitioned into Macintosh HD and Data
The application starts, uses information from the Data volume during
initialization, and then gets a notification that /Volumes/Data was
mounted.
As far as the framework is concerned, this is "news" to your
application because your application, being new to the world, is
totally ignorant as to the state of mounted volumes. And the fact
that your app has already accessed the Data volume is irrelevant. The
DiskArbitration notifications are received and processed
asynchronously with respect to the actual mounting of the volume. Even
for a newly mounted volume, your app could access it before receiving
the notification if it were quick about (or even slow about it, if it
just doesn't let its run loop run).
The system is configured to automatically log in the user and my
application is a Login Item.
Based on reading "System Startup Programming Topics" it occurred to
me that possibly the Finder and my application are launching
simultaneously and that the notification is originating in the
Finder when it notices the second volume. Relaunching the Finder
does not produce another notification.
Such notifications do not come from the Finder and what you're seeing
has nothing to do with when the Finder launches, or when your app
launches. The Finder is just another client of the DiskArbitration
server, just like your app.
Regards,
Ken
_______________________________________________
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