2

问题是“成功”总是让我返回错误?我不知道是什么问题?

我的代码如下:

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];
4

3 回答 3

0

参考文档说:

返回值

YES选项菜单是否显示或未显示NO。如果菜单中没有合适的项目,则可能不会显示选项菜单。

我认为您的%3F1340297029后缀currentPDFPath可能会阻止UTI匹配。

检查 的UTI属性,如果是 则docController设置为。kUTTypePDFnil

于 2012-07-02T12:59:29.963 回答
0

您的崩溃问题可能是因为您的 docController 已经发布。您需要保留它,然后稍后自动释放它。看看这里:

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

于 2012-08-19T13:04:07.137 回答
0

我稍微修改了您的代码,但它不适合我,我使用的是 ARC,所以您必须更改它以适合您的非 ARC 代码。

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

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

                    NSLog(@"Applications were found");
                }

BOOL是返回YESNOYES它后面的行是=TRUE如果NO行是FALSE

- 大卫

于 2013-09-08T07:41:40.037 回答