AEInstallEventHandler handler not being called on startup

匆匆过客 提交于 2019-12-11 10:24:13

问题


I've installed a Apple Event handler for URL's in my app:

OSStatus e = AEInstallEventHandler( kInternetEventClass,
                            kAEGetURL,
                            NewAEEventHandlerUPP(AppleEventProc),
                            (SRefCon)this,
                            false);

And that works if my application is running. However if my app is NOT running, clicking a URL in a browser starts the application but no Apple Event is received on my handler. My call to AEInstallEventHandler is during my app's startup phase, before it reaches the message loop. It's not the very first thing I do, but not too far off it. (Obviously I've setup the plist correctly, as I'm getting events while running)

Any ideas on how to get this working?

Interestingly when Chrome starts my to handle a mailto URL it passes "-psn_0_5100765" on the command line. Which doesn't mean anything to me, does anyone know what it's trying to tell me?

Note: I've setup Apple Event debugging and run it again. I'm definitely getting sent a GURL event on startup, after I have installed the callback handler. However I still can't work out why my callback is not called with that Event.


回答1:


So I have some code using ReceiveNextEvent:

    while
    (
        ReceiveNextEvent
        (
            0,
            NULL,
            0.001, // kEventDurationForever,
            kEventRemoveFromQueue,
            &theEvent
        )
        ==
        noErr
    )
    {
        SendEventToEventTarget(theEvent, theTarget);
        ReleaseEvent(theEvent);
    }   

That is called a number of times during application startup. What is happening is the processing of these events is not taking into account the need to call AEProcessEvent for kEventAppleEvent events. This is done automatically inside RunApplicationEventLoop, but you have to do it manually if you use a ReceiveNextEvent loop. So I've added that to my loop like this:

    while
    (
        ReceiveNextEvent
        (
            0,
            NULL,
            0.001, // kEventDurationForever,
            kEventRemoveFromQueue,
            &theEvent
        )
        ==
        noErr
    )
    {
        if (GetEventKind(theEvent) == kEventAppleEvent)
            AEProcessEvent(theEvent);

        SendEventToEventTarget(theEvent, theTarget);
        ReleaseEvent(theEvent);
    }   

And now it works at start up AND during run time.

Uli Kusterer was responsible for pointing me in the right direction. So many thanks to him.



来源:https://stackoverflow.com/questions/8265487/aeinstalleventhandler-handler-not-being-called-on-startup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!