gpt4 book ai didi

macos - PDF文档删除PageAtIndex : is not working when updated to Mac OS X 10. 11

转载 作者:行者123 更新时间:2023-12-03 16:14:59 26 4
gpt4 key购买 nike

enter image description here enter image description here

我正在我的 PDFViewer cocoa 应用程序中使用 PDFKit 框架。当我尝试从 PDFDocument 中删除其中一页时,应用程序卡住在代码行

[[self pdfDocument]  removePageAtIndex:0]; // can see this Problem only in Mac OS X 10.11

当我在 Mac OS X 10.10 中运行该应用程序时,效果非常好

我阅读了所有相关的苹果文档,但还没有得到任何解决方案。

这是回溯:

* thread #1: tid = 0x85e1, 0x00007fff92571f5e libsystem_kernel.dylib`__psynch_cvwait + 10, queue = 'com.apple.main-thread', stop reason = signal SIGTERM
frame #0: 0x00007fff92571f5e libsystem_kernel.dylib`__psynch_cvwait + 10
frame #1: 0x00000001006c05f7 libsystem_pthread.dylib`_pthread_cond_wait + 767
frame #2: 0x00007fff904c6e32 Foundation`-[__NSOperationInternal _waitUntilFinished:] + 131
frame #3: 0x00007fff904921fa Foundation`-[NSOperationQueue waitUntilAllOperationsAreFinished] + 254
* frame #4: 0x000000010017efe1 Neat`-[NRMPDFCoordinator waitUntilAllOperationsAreFinished](self=0x0000608000ad3be0, _cmd=0x00007fff8877e285) + 145 at NRMPDFCoordinator.m:1362
frame #5: 0x00000001000109cf Neat`-[NRMItemEditorDocument saveDocumentWithDelegate:didSaveSelector:contextInfo:](self=0x000060000094a190, _cmd=0x00007fff88777581, delegate=0x0000000000000000, didSaveSelector=0x0000000000000000, contextInfo=0x0000000000000000) + 1151 at NRMItemEditorDocument.m:325
frame #6: 0x000000010001018a Neat`-[NRMItemEditorDocument saveDocument:](self=0x000060000094a190, _cmd=0x00007fff8874cbb4, sender=0x00006080003a8b20) + 58 at NRMItemEditorDocument.m:234
frame #7: 0x0000000100013bef Neat`-[NRMItemEditorWindowController saveAndClose:](self=0x00006080003a8b20, _cmd=0x00000001002cf2d2, sender=0x000060000094a5b0) + 95 at NRMItemEditorWindowController.m:244
frame #8: 0x00007fff87068082 libsystem_trace.dylib`_os_activity_initiate + 75
frame #9: 0x00007fff87fc79b5 AppKit`-[NSApplication sendAction:to:from:] + 460
frame #10: 0x00007fff87fd9bb2 AppKit`-[NSControl sendAction:to:] + 86
frame #11: 0x00007fff87fd9adc AppKit`__26-[NSCell _sendActionFrom:]_block_invoke + 131
frame #12: 0x00007fff87068082 libsystem_trace.dylib`_os_activity_initiate + 75
frame #13: 0x00007fff87fd9a39 AppKit`-[NSCell _sendActionFrom:] + 144
frame #14: 0x00007fff87068082 libsystem_trace.dylib`_os_activity_initiate + 75
frame #15: 0x00007fff87fd805e AppKit`-[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2693
frame #16: 0x00007fff88020d1c AppKit`-[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 744
frame #17: 0x00007fff87fd6788 AppKit`-[NSControl mouseDown:] + 669
frame #18: 0x00007fff88524575 AppKit`-[NSWindow _handleMouseDownEvent:isDelayedEvent:] + 6322
frame #19: 0x00007fff88525559 AppKit`-[NSWindow _reallySendEvent:isDelayedEvent:] + 212
frame #20: 0x00007fff87f6ad31 AppKit`-[NSWindow sendEvent:] + 517
frame #21: 0x00007fff87eeaccb AppKit`-[NSApplication sendEvent:] + 2540
frame #22: 0x0000000100225f35 Neat`-[NRMApplication sendEvent:](self=0x00006000001205a0, _cmd=0x00007fff88749e04, event=0x0000608000725640) + 1141 at NRMApplication.m:95
frame #23: 0x00007fff87d51f3e AppKit`-[NSApplication run] + 796
frame #24: 0x00007fff87d1b162 AppKit`NSApplicationMain + 1176
frame #25: 0x0000000100012d67 Neat`main(argc=3, argv=0x00007fff5fbff718) + 119 at main.m:21
frame #26: 0x0000000100001e74 Neat`start + 52

这是我使用PDFDocument的removePageAtIndex方法的方法

-(NSError *)removePageOpImpl:(NRMPDFOperation *)op
{
NSLog(@"\n Inside removePageOpImpl Method ...");
NSError* error = [self loadDocument];
if( !error )
{
NSUInteger index = [self pageIndexForId:[op pageId]];
NSLog(@"Page count: %ld", [self pageCount]);
if( index < [self pageCount] )
{
NSLog(@"PDF Document:-- %@", [self pdfDocument]);
NSLog(@"Index is: %ld", index);
@try {

[(PDFDocument *)[self pdfDocument] removePageAtIndex:index];//At this line the app getting freezed and control is ended.

NSLog(@"Page count after delete: %ld", [self pageCount]);


}
@catch (NSException *exception) {
NSLog(@"Exception: %@", exception);
}
@finally {
NSLog(@"Finally called");
[[self mutablePageIdList] removeObjectAtIndex:index];
[self updatePageLabelsFromIndex:index];
[self updateChangeCount:NSChangeDone];
self.contentsChanged = YES;
}
}
else
{
// TODO: error
}
}
return error;
}

任何人都可以建议我可能是什么问题...还附上了阻塞 UI 的队列的屏幕截图

我尝试将主队列上的dispatch_async应用于PDFDocument页面删除操作,如下所示

- (NSError *)removePageOpImpl:(NRMPDFOperation *)op
{
NSError* error = [self loadDocument];
if( !error )
{
NSUInteger index = [self pageIndexForId:[op pageId]];
if( index < [self pageCount] )
{
dispatch_async(dispatch_get_main_queue(), ^{
[[self pdfDocument] removePageAtIndex:index];
[[self mutablePageIdList] removeObjectAtIndex:index];
[self updatePageLabelsFromIndex:index];
[self updateChangeCount:NSChangeDone];
self.contentsChanged = YES;

});
}
else
{
// TODO: error
}
}
return error;
}

现在应用程序没有挂起,但我遇到了另一个问题。我还有其他操作应该在removePageOpImpl 操作之后同步运行。但它们是在removePageOpImpl完成之前执行的,这正在改变我的应用程序的行为。你能建议我如何在removePageOpImpl之后同步执行其他操作吗?我读到了有关完成处理程序的内容,但是在这种情况下我对如何使用它感到困惑。

请提出建议

最佳答案

你在这里造成了一个很好的小僵局。

您的主线程正在等待操作完成,但该操作(由此跟踪指示)...

enter image description here

正在后台线程上运行,正如您所看到的,它正在等待一个信号量,该信号量很可能只会从主线程发出信号。这具有类似于主线程的 dispatch_sync 之类的标记。由于它发生在 PDFDocument 实现内部,我想它试图确保它在返回给用户之前在主线程上运行某些内容(读取器/写入器锁

因此,您的主线程正在等待一个操作完成,而该操作正在等待主线程完成它正在尝试执行的操作。经典的僵局。

发生这种情况是因为主线程启动保存,然后等待一切完成后再继续(但其他一些工作也需要在主线程上运行)。

您需要将保存作为异步操作启动,因此在等待操作完成时它不会在主线程上运行。然后,当保存完成后,如果您必须更新 UI,它可以通过主线程上运行的完成 block 或委托(delegate)来报告其成功/失败。

关于macos - PDF文档删除PageAtIndex : is not working when updated to Mac OS X 10. 11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33253779/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com