PDFDocument removePageAtIndex: does not work when upgrading to Mac OS X 10.11

enter image description here enter image description here

I am using the PDFKit Framework in my cocoa application for PDFViewer. When I try to delete one of the pages from the PDFDocument, the application freezes in the line of code

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

This works great when I run the application on Mac OS X 10.10

I have read all the related Apple documents, but I have not received any solution yet.

Here is the back trace:

* 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

here is the method in which i use the removePageAtIndex PDFDocument method

-(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;
}

Can someone please suggest me what might be the problem ... also added screenshots of the queues that blocked the user interface

I tried applying dispatch_async in the main queue to delete PDFDocument page operations as shown below

- (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. , , .

,

+4
1

.

, ( )...

enter image description here

, , , , , . - dispatch_sync. PDFDocument, , , - , ( /

, , , . .

- , , ( ).

, , . , , , / , .

+2

Source: https://habr.com/ru/post/1612545/


All Articles