0

Posting after finding answer

After "rubber duck debugging" this answer a bunch, I finally came across the correct answer on a question that appears to me to be unrelated. I think this question (and its answer) are still relevant, so I'm posting the question and will post my own answer to hopefully help others like me.


I am creating a PDF in my iOS app that I would like to allow the user to export. For the purposes of this testing, I'm trying to save it to my personal Dropbox on a physical device.

I have turned on iTunes file sharing, and I can verify that the PDF file is being generated correctly, and when I copy it off of my device (iPad Pro Gen. 2 running iOS 11), I can open the PDF and it has the expected content and appearance.

I am able to get the document pop-up to display correctly, and I have options to share via:

  • Line 1: AirDrop
  • Line 2: Message, Mail, Add to Notes, (Facebook) Messenger, etc.
  • Line 3: Copy, Print, Save to Files, Save to Dropbox, etc.

No matter what I try to select (Save to Dropbox is the one I want to solve, but the issue seems universal), it fails. Of note, when I click Save to Dropbox, I do see the Dropbox panel display, but there is immediately a modal over top of the Save to Dropbox modal that says, "An unknown error occurred."

I have tried to look around and see how to get more information about this error, but I'm stumped. I'm not sure if it's correlated, but I get this message in the console:

[AXRun-PID] Client requesting unsuspension of PID:813 Name:<redacted>

Trying to google that error has proved unfruitful.

Here's the code where I generate the PDF and show the menu:

#pragma mark • Sharing Methods
- (void)showShareMenu {
    NSArray *bookList = [BookManager bookList];
    NSURL *pdfUrl     = [PdfGenerator generatePdfFromBooks:bookList];
    UIDocumentInteractionController *vc = [[UIDocumentInteractionController alloc] init];
    vc.name = @"Booklet.pdf";
    vc.URL  = pdfUrl;
    vc.UTI  = @"com.adobe.pdf";
    [vc presentOptionsMenuFromBarButtonItem:self.navigationItem.leftBarButtonItem animated:YES];
}

I've tried using UIDocumentInteractionController *vc = [UIDocumentInteractionController interactionControllerWithURL:pdfUrl]; instead of the one above, but the results are the same.

I tried making self the delegate of vc and then tried to implement the following methods:

- (void)documentInteractionController:(UIDocumentInteractionController *)controller 
        willBeginSendingToApplication:(nullable NSString *)application;
- (void)documentInteractionController:(UIDocumentInteractionController *)controller 
           didEndSendingToApplication:(nullable NSString *)application;

Neither of those methods ever fired.

Interestingly, though I think I've supplied the file name correctly based on what I've read, the name in the File textbook in the Save to Dropbox modal is a current timestamp (e.g., File Oct 28, 11 12 22 PM). The Dropbox modal stays up until I click "OK" on the "An unknown error occurred" modal, and then disappears immediately.

It seems like I'm somehow not providing the right information, but I'm not sure how. It seems like there ought to be a delegate method to indicate an error to me, but I don't see anything like that in the docs. (It is late, and I have been looking at this for hours, including reading several related tutorials, so I could have missed something obvious.)

mbm29414
  • 11,558
  • 6
  • 56
  • 87

1 Answers1

0

I came across this answer as an example question while asking this current question.

It doesn't really ask the same question I have, nor did that user have the same error outputs I did. But, the linked answer did work for me, too.

The problem I had in the code above was that I was not keeping the UIDocumentInteractionController around after I created it. Adding a private property fixed this issue. So, the following code now works:

#pragma mark • Sharing Methods
- (void)showShareMenu {
    NSArray *bookList       = [BookManager bookList];
    NSURL *pdfUrl           = [PdfGenerator generatePdfFromBooks:bookList];
    self.docController      = [UIDocumentInteractionController interactionControllerWithURL:pdfUrl];
    self.docController.name = @"Booklet.pdf";
    self.docController.UTI  = @"com.adobe.pdf";
    [self.docController presentOptionsMenuFromBarButtonItem:self.navigationItem.leftBarButtonItem animated:YES];
}
mbm29414
  • 11,558
  • 6
  • 56
  • 87