启动时未调用AEInstallEventHandler处理程序 [英] AEInstallEventHandler handler not being called on startup

查看:116
本文介绍了启动时未调用AEInstallEventHandler处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的应用中为URL安装了Apple Event处理程序:

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

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

如果我的应用程序正在运行,那将起作用.但是,如果我的应用程序未运行,则在浏览器中单击URL会启动该应用程序,但我的处理程序未收到任何Apple Event.我对AEInstallEventHandler的调用是在应用程序的启动阶段,即到达消息循环之前.这不是我要做的第一件事,但是距离我也不远. (显然,我已经正确设置了plist,因为我在运行时会收到事件)

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?

有趣的是,当Chrome启动我来处理mailto URL时,它在命令行上传递了"-psn_0_5100765".这对我来说没有任何意义,有人知道它要告诉我什么吗?

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?

注意:我已经设置了Apple Event调试并再次运行它.安装回调处理程序后,我肯定会在启动时收到GURL事件.但是我仍然无法弄清楚为什么该事件未调用我的回调.

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.

推荐答案

所以我有一些使用ReceiveNextEvent的代码:

So I have some code using ReceiveNextEvent:

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

在应用程序启动期间被多次调用.正在发生的情况是,这些事件的处理未考虑为kEventAppleEvent事件调用AEProcessEvent的需要.这是在RunApplicationEventLoop内部自动完成的,但是如果使用ReceiveNextEvent循环,则必须手动进行.因此,我将其添加到了我的循环中,如下所示:

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 负责向我指出正确的方向.非常感谢他.

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

这篇关于启动时未调用AEInstallEventHandler处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆