How to implement notifications
How to implement notifications
- Subject: How to implement notifications
- From: Bill Cheeseman <email@hidden>
- Date: Fri, 15 Nov 2002 11:46:13 -0500
I'm stuck trying to get accessibility notifications to work in my Cocoa app.
I suspect the problem is due to one of these errors: (1) I'm declaring or
calling my callback function incorrectly, or (2) I'm not adding the observer
to the run loop correctly. All help gladly accepted!
Here are the essential features of my code:
1. I declare the callback function in myClass.h like so:
void observerCallbackFunction(AXObserverRef observer, AXUIElementRef
element, CFStringRef notification, void *refcon);
2. I define the callback function in myClass.m like so:
void observerCallbackFunction(AXObserverRef observer, AXUIElementRef
element, CFStringRef notification, void *refcon) {
NSLog(@"notification = %@", (NSString *)notification);
}
3. I create a new observer by calling the following in a Cocoa method:
AXObserverRef observer;
AXError err = AXObserverCreate(pid, observerCallbackFunction, &observer);
4. Right after creating the observer, I add it to the run loop like this:
CFRunLoopAddSource(CFRunLoopGetCurrent(),
AXObserverGetRunLoopSource(observer), kCFRunLoopDefaultMode);
5. I register a notification with the observer in another Cocoa method like
this:
AXError err = AXObserverAddNotification(observer, element,
(CFStringRef)notification, info);
In debugging, I've verified that observer, element, notification, and pid
are correct (I don't care about refcon for the moment). In particular, I've
verified that the observer created and the observer registered are one and
the same observer. At run time, I register notification
NSAccessibilityWindowCreatedNotification on element AXApplication in the
target application. My app runs without generating any error messages, and
it doesn't crash. It correctly reads the screen and triggers actions in the
target application. But my callback function is never called and I receive
no notifications.
I am not confident that I understand the documentation for AXObserverCreate,
especially with respect to the callback function prototype and its correct
usage.
And I know I don't understand the Core Foundation run loop stuff, except
that people tell me I should be able to use it because Cocoa's runloop sits
on top of Core Foundation's. In Cocoa, I think I would have to create a
port, add it to the runloop, and maybe do some other things. Do I have to do
anything like that when using the Core Foundation CFRunLoopAddSource
function?
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
The AppleScript Sourcebook -
http://www.AppleScriptSourcebook.com
Vermont Recipes -
http://www.stepwise.com/Articles/VermontRecipes
Croquet Club of Vermont -
http://members.valley.net/croquetvermont
_______________________________________________
accessibility-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/accessibility-dev
Do not post admin requests to the list. They will be ignored.