3

Th problem is that "success" is always return me false? I do not what is the problem?

my code as follows:

UIDocumentInteractionController *docController = [[UIDocumentInteractionController interactionControllerWithURL:currentPDFPath] retain];

if (docController)
{
    docController.delegate = self;

    BOOL success = [docController presentOptionsMenuFromBarButtonItem:openInButton animated:YES]; 
    //BOOL success = [docController presentOpenInMenuFromBarButtonItem:openInButton animated:YES];
    NSLog(@"success: %d", success);
    if(!success)
    {
        UIAlertView * noApps = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Your iPad doesn't seem to have any other Apps installed that can open this document (such as iBooks)" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

        [noApps show];
        [noApps release];

    }
}
    [docController release];
Priyanka Chhetri
  • 311
  • 2
  • 5
  • 14

3 Answers3

0

The class reference documentation says:

Return Value

YES if the options menu was displayed or NO if it was not. The options menu may not be displayed in cases where there are no appropriate items to include in the menu.

I think your %3F1340297029 suffix on currentPDFPath may be preventing a UTI match.

Check the UTI property of docController and set to kUTTypePDF if it is nil.

Community
  • 1
  • 1
PhilMY
  • 2,621
  • 21
  • 29
  • Thanks for replying.My this problem is resolved. Now "BOOL success" is returning 1. But I am not able to open this pdf in iBook. – Priyanka Chhetri Jul 02 '12 at 16:19
  • Now the error is "*** Terminating app due to uncaught exception 'NSGenericException', reason: '-[UIPopoverController dealloc] reached while popover is still visible." – Priyanka Chhetri Jul 02 '12 at 16:21
0

Your crashing issue is probably because your docController has already been released. You'll need to retain it and then autorelease it later. Have a look here:

https://stackoverflow.com/a/3474825/523350

Community
  • 1
  • 1
Stewart Macdonald
  • 2,062
  • 24
  • 27
0

I modified your code a bit, not it is working for me, I am using ARC, so you have to change it to fit your non-ARC code.

BOOL success = [self.documentInteractionController presentOpenInMenuFromRect:rect inView:self.view animated:YES];

                if (success == NO) {
                    NSLog(@"No application was found");
                } else {

                    NSLog(@"Applications were found");
                }

The BOOL is either returning YES or NO, YES it the line behind the = is TRUE and NO if the line is FALSE.

--David

David Gölzhäuser
  • 3,525
  • 8
  • 50
  • 98