I'm writing preferences for my app which registers it for launch at login (using LSSharedItemList
API). All goes fine and my app toggles its presence in user's login items upon checkbox status. Now I want to tackle another problem when user actually removes the开发者_如何学Python app from "Login items" in Accounts.prefPane
.
Using Notification Watcher I see that distributed notification center sends com.apple.loginItemsListDidChnage
(mind the typo) notification, hence I add observer for that notification with same selector (which is IBAction
) that handles checkbox in preferences window (which, actually, [un]registers the app from/to login items).
The problem appears when I try to compare the class of the sender of the action that toggles my app as login item. Using [sender description]
and [sender class]
I see NSConcreteNotification
class, but as soon as I try to do comparison upon it - code breaks saying that there is no such class defined:
if ([[sender class] isEqualTo:[NSConcreteNotification class]]) {
...
}
If I try to compare sender to NSNotification
- then flow doesn't fall into that branch.
Maybe I'm missing some essential knowledge on distributed notifications in Mac OS X?
Running Mac OS X 10.6.2
NSConcreteNotification
is a private subclass of the abstract NSNotification
class. You are not supposed to use the NSConcreteNotification
class. If you want to check if a class is an NSNotification
, use -isKindOfClass:
:
if ([sender isKindOfClass:[NSNotification class]]) {
...
}
精彩评论