我的应用程序在其应用程序委托中实现了 NSApplicationDelegate 方法 -application:openFile:。OS 10.8 似乎有一个新问题,在接收到打开文件的苹果事件后,在某种内部超时被击中之前经过 5 秒,向苹果事件发送响应,调用应用程序(例如,applescript编辑)收益。
详细地说,这就是我所看到的。在 application:openFile: 返回 YES 之后,我可以看到 -[NSAppleEventManager suspendCurrentAppleEvent] 被调用:
#0 0x00007fff8f07b5ed in -[NSAppleEventManager suspendCurrentAppleEvent] ()
#1 0x00007fff8f90458e in -[NSApplication(NSAppleEventHandling) _handleAEOpenDocumentsForURLs:] ()
#2 0x00007fff8f903b55 in -[NSApplication(NSScripting) handleOpenScriptCommand:] ()
#3 0x00007fff90770cac in __invoking___ ()
#4 0x00007fff90770b47 in -[NSInvocation invoke] ()
#5 0x00007fff90770d19 in -[NSInvocation invokeWithTarget:] ()
#6 0x00007fff8f10121c in -[NSScriptCommand _sendToRemainingReceivers] ()
#7 0x00007fff8f1014c6 in -[NSScriptCommand executeCommand] ()
#8 0x00007fff8f11983a in -[NSScriptingAppleEventHandler handleCommandEvent:withReplyEvent:] ()
#9 0x00007fff8f00635b in -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] ()
#10 0x00007fff8f0061bd in _NSAppleEventManagerGenericHandler ()
#11 0x00007fff93844f68 in aeDispatchAppleEvent ()
#12 0x00007fff93844dc9 in dispatchEventAndSendReply ()
#13 0x00007fff93844c89 in aeProcessAppleEvent ()
#14 0x00007fff8c141e29 in AEProcessAppleEvent ()
#15 0x00007fff8f6b22a6 in _DPSNextEvent ()
#16 0x00007fff8f6b1862 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()
#17 0x00007fff8f6a8c03 in -[NSApplication run] ()
#18 0x00007fff8f64d656 in NSApplicationMain ()
#19 0x0000000100001d7c in main (argc=3, argv=0x7fff5fbff7c0) at main.m:23
五秒钟后,-[NSAppleEventManager resumeWithSuspensionID:] 被调用:
#0 0x00007fff8f07b6be in -[NSAppleEventManager resumeWithSuspensionID:] ()
#1 0x00007fff8f90585f in __block_global_1 ()
#2 0x00007fff9073a4b4 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ ()
#3 0x00007fff90739fcd in __CFRunLoopDoTimer ()
#4 0x00007fff9071f7b9 in __CFRunLoopRun ()
#5 0x00007fff9071edd2 in CFRunLoopRunSpecific ()
#6 0x00007fff8c137774 in RunCurrentEventLoopInMode ()
#7 0x00007fff8c137512 in ReceiveNextEventCommon ()
#8 0x00007fff8c1373a3 in BlockUntilNextEventMatchingListInMode ()
#9 0x00007fff8f6b1fa3 in _DPSNextEvent ()
#10 0x00007fff8f6b1862 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()
#11 0x00007fff8f6a8c03 in -[NSApplication run] ()
#12 0x00007fff8f64d656 in NSApplicationMain ()
#13 0x0000000100001d7c in main (argc=3, argv=0x7fff5fbff7c0) at main.m:23
显然,由于 resumeWithSuspensionID: 是从计时器调用的,并且在我的 application:openFile: 方法返回和 resumeWithSuspensionID: 被调用之间总是非常接近 5 秒,因此达到了某种超时。
在此之后,一切正常进行:无论 applescript 调用什么“打开文件 ...”,都将在下一条语句中继续。似乎没有任何错误 - 它只是超时等待某些东西。
我打开了 AEDebugSends 和 AEDebugReceives。这是我看到的超时:
Aug 23 21:26:05 mymachine.local iTerm[4819] <Info>: _aeMachPortCallback(), got a message, @ 0x0x7fff5fbfe1f0 size=972 info=0 (_aeMachPortCallback()/AEMach.cp #643) main
Aug 23 21:26:05 mymachine.local iTerm[4819] <Notice>: AE2000 (4819: Received an event:
------oo start of event oo------
aevt('aevt'\'odoc' transactionID=0 returnID=3711 sourcePSN=[0x0,6f06f "AppleScript Editor"] eventSource=3 sourceUID=501 sourceGID=20 sourceEUID=501 sourceEGID=20 sourcePID=3551 auditToken=[501,501,20,501,20,3551,100005,3551]{ '----':obj ('obj '{ 'form':enum('name'), 'want':type('file'), 'seld':utxt('utxt'(TEXT("Macintosh HD:Users:georgen:Library:Application Support:iTerm:version.txt"))), 'from':null() }), &'csig':magn(65536) })
------oo end of event oo------
(aeProcessIncomingEvent()/AEMach.cp #1445) main
2012-08-23 21:26:05.451 iTerm[4819:707] Command: NSCoreSuite.Open
Direct Parameter: /Users/georgen/Library/Application Support/iTerm/version.txt
Receivers: (null)
Arguments: {
"" = "/Users/georgen/Library/Application Support/iTerm/version.txt";
}
然后,在超时后我看到了这个(因为我也将 NSScriptingDebugLogLevel 设置为 1 而记录了它):
2012-08-23 21:26:36.347 iTerm[4819:707] Result: <null>
我的 openFile: 方法除了返回 YES 什么都不做。我还需要做些什么来使框架满意吗?