【问题标题】:presentOpenInMenuFromRect not working DocumentHandler.h - QuickLookpresentOpenInMenuFromRect 不工作 DocumentHandler.h - QuickLook
【发布时间】:2014-11-19 22:50:14
【问题描述】:

我正在使用 documenthandler cordova 插件,如果我单击按钮,我会从工作正常的 url 获取文档处理程序中的 pdf,这样我就可以将 pdf 保存到 iBooks 中。

现在,我需要能够在不打开文档的情况下触发共享按钮,而不是在查看器中打开文档并单击共享按钮,然后再次单击以保存到 iBooks。我知道这可以使用presentOpenInMenuFromRect 而不是presentViewController 来完成,但由于某种原因它不起作用,代码如下:

#import "DocumentHandler.h"

@implementation DocumentHandler

- (void)HandleDocumentWithURL:(CDVInvokedUrlCommand*)command;
{
    CDVPluginResult *commandResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@""];

    __weak DocumentHandler* weakSelf = self;

    dispatch_queue_t asyncQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_async(asyncQueue, ^{

        NSDictionary* dict = [command.arguments objectAtIndex:0];

        NSString* urlStr = dict[@"url"];
        NSURL* url = [NSURL URLWithString:urlStr];
        NSData* dat = [NSData dataWithContentsOfURL:url];
        NSString* fileName = [url lastPathComponent];
        NSString* path = [NSTemporaryDirectory() stringByAppendingPathComponent: fileName];
        NSURL* tmpFileUrl = [[NSURL alloc] initFileURLWithPath:path];
        [dat writeToURL:tmpFileUrl atomically:YES];
        weakSelf.fileUrl = tmpFileUrl;

        dispatch_async(dispatch_get_main_queue(), ^{
            QLPreviewController* cntr = [[QLPreviewController alloc] init];
            cntr.delegate = weakSelf;
            cntr.dataSource = weakSelf;

            UIViewController* root = [[[UIApplication sharedApplication] keyWindow] rootViewController];

            [root presentViewController:cntr animated:YES completion:nil];//this works fine and open the document with share button

            CGRect rect = CGRectMake(0, 0, 1024, 768);
            [root presentOpenInMenuFromRect:rect inView:self.view animated:YES]; // this doesn't work where
            //I want to see only sharing options
            //here are errors,one of them is /Property'view' not found on object of type ''DocumentHandler
        });


        [weakSelf.commandDelegate sendPluginResult:commandResult callbackId:command.callbackId];
    });
}



#pragma mark - QLPreviewController data source

- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller
{
    return 1;
}

- (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index
{
    return self;
}

#pragma mark - QLPreviewItem protocol

- (NSURL*)previewItemURL
{
    return self.fileUrl;
}

@end

我需要帮助:(

编辑:查看我想要实现的图像:

【问题讨论】:

    标签: ios cordova quicklook presentviewcontroller


    【解决方案1】:

    presentOpenInMenuFromRect 是一个UIDocumentInteractionController 方法。我不认为你在这段代码中使用了一个,除非你的根视图控制器是UIDocumentInteractionController,这会非常非常奇怪。

    不是实例化和呈现QLPreviewController,而是实例化UIDocumentInteractionController,并从与文档图标对应的矩形呈现弹出框。

    为此,请查看UIDocumentInteractionController documentation。您会看到有一个interactionControllerWithURL: 方法,您可以使用它来实例化指向您的文件的UIDocumentInteractionController。然后你可以调用 presentOpenInMenuFromRect:inView:animated: 来显示你想要的弹出框。

    【讨论】:

    • 感谢您的回复。但是,我是 iOS 新手,我不确定如何实施您的解决方案。你能帮我怎么做吗?非常感谢
    • 我添加了整个 DocumentHandler.h 代码。你能帮忙吗?
    • 我添加了我需要得到的图片。
    • 好的,我实际上决定继续使用 QLPreviewController。现在,有没有办法可以自定义它?比如改变工具栏中的颜色?而不是白色?另外,我的最后一个问题是,有没有办法自定义它,所以 QLPreviewController 将具有类似于 iBooks 中的文本搜索功能?非常感谢您的回答。
    • 不,QLPreviewController 不可自定义。不过,您可以使用UIWebView 来显示您感兴趣的文档并围绕它构建您想要的 UI。它支持与 Quick Look 相同的文档类型。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-08
    • 2011-04-14
    • 2016-06-22
    • 1970-01-01
    • 2012-08-08
    相关资源
    最近更新 更多