Search code examples
iosobjective-cuipopovercontrolleribooksuidocumentinteraction

Objective C: Opening A PDF File on iBooks


I am downloading a PDF file from an online server and save it to my the App's Sandbox then view it in iBooks.

The iBooks viewing is what i am struggling now. I tried this code:

    UIDocumentInteractionController *docController = [UIDocumentInteractionController interactionControllerWithURL:url];

    docController.delegate = self;

    [docController presentOpenInMenuFromRect:savePDF.frame inView:self.view animated:YES];
    [docController dismissMenuAnimated:YES];

Still gor no chance, It is running but the popover is being dismissed right away after it was presented. But when I deleted [docController dismissMenuAnimated:YES]; it gives me an error saying '-[UIPopoverController dealloc] reached while popover is still visible.'

What could be the problem?


Solution

  • The problem is that your UIDocumentInteractionController is being released right after being presented, due to the variable docController no longer being in scope.

    To prevent that, you should create a strong property or an instance variable and store your UIDocumentInteractionController in there. That way, the UIDocumentInteractionController will stick around until you release the object controlling it, which should be long enough for the user to make a selection...