Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios PresentOpenMinumeFromRect不工作DocumentHandler.h-QuickLook_Ios_Cordova_Quicklook_Presentviewcontroller - Fatal编程技术网

Ios PresentOpenMinumeFromRect不工作DocumentHandler.h-QuickLook

Ios PresentOpenMinumeFromRect不工作DocumentHandler.h-QuickLook,ios,cordova,quicklook,presentviewcontroller,Ios,Cordova,Quicklook,Presentviewcontroller,我正在使用documenthandler cordova插件,如果我单击按钮,我会从url中获取文档处理程序中的pdf,这很好,这样我就可以将pdf保存到iBooks中 现在,我需要能够在不打开文档的情况下触发共享按钮,而不是在查看器中打开文档并单击共享按钮,然后再次单击以保存到iBooks中。我知道这可以使用presentOpenMinumeFromRect而不是presentViewController来完成,但由于某些原因,它不起作用,代码如下: #import "DocumentHand

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

现在,我需要能够在不打开文档的情况下触发共享按钮,而不是在查看器中打开文档并单击共享按钮,然后再次单击以保存到iBooks中。我知道这可以使用
presentOpenMinumeFromRect
而不是
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
#导入“DocumentHandler.h”
@实现文档处理程序
-(void)HandleDocumentWithURL:(CDVInvokedUrlCommand*)命令;
{
CDVPluginResult*commandResult=[CDVPluginResult resultWithStatus:CDVCommandStatus_确定消息字符串:@”“];
__弱DocumentHandler*weakSelf=self;
调度队列异步队列=调度获取全局队列(调度队列优先级默认为0);
调度异步(异步队列^{
NSDictionary*dict=[command.arguments objectAtIndex:0];
NSString*urlStr=dict[@“url”];
NSURL*url=[NSURL URLWithString:urlStr];
NSData*dat=[NSData datawithcontentsofull:url];
NSString*文件名=[url lastPathComponent];
NSString*path=[NSTemporaryDirectory()stringByAppendingPathComponent:fileName];
NSURL*tmpFileUrl=[[NSURL alloc]initFileURLWithPath:path];
[dat writeToURL:tmpFileUrl原子性:是];
weakSelf.fileUrl=tmpFileUrl;
dispatch\u async(dispatch\u get\u main\u queue()^{
QLEVIEWCONTROLLER*cntr=[[QLEVIEWCONTROLLER alloc]init];
cntr.delegate=weakSelf;
cntr.dataSource=weakSelf;
UIViewController*root=[[[UIApplication sharedApplication]keyWindow]rootViewController];
[root presentViewController:cntr-animated:YES-completion:nil];//这可以正常工作,并使用“共享”按钮打开文档
CGRect rect=CGRectMake(0,0,1024768);
[root presentOpenMinumeFromRect:rect-inView:self.view-animated:YES];//这在哪里不起作用
//我只想看到共享选项
//以下是错误,其中一个错误是在类型为“”DocumentHandler的对象上找不到/Property“view”
});
[weakSelf.commandDelegate sendPluginResult:commandResult callbackId:command.callbackId];
});
}
#pragma标记-QLPreviewController数据源
-(NSInteger)PreviewWitemsInPreviewController的编号:(QLPreviewController*)控制器
{
返回1;
}
-(id)previewController:(QLPreviewController*)控制器PreviewWitematindex:(NSInteger)索引
{
回归自我;
}
#pragma-mark-qlwitem协议
-(NSURL*)预览
{
返回self.fileUrl;
}
@结束
我需要帮助,请:(

编辑:查看我试图实现的图像:


PresentOpenMinumeFromRect
是一种
UIDocumentInteractionController
方法。我认为您在这段代码中没有使用这种方法,除非您的根视图控制器是一个
UIDocumentInteractionController
,这会非常奇怪

不要实例化和显示
qlviewcontroller
,而是实例化
UIDocumentInteractionController
,并从对应于文档图标的rect中显示popover

为此,请查看。您将看到有一个
interactionControllerWithURL:
方法,可用于实例化指向您的文件的
UIDocumentInteractionController
。然后您可以调用


PresentOpenMinumeFromRect:inView:animated:
以显示您想要的popover。

谢谢您的回复。但是,我是iOS新手,不知道如何实现您的解决方案。您能帮我做吗?非常感谢我添加了整个DocumentHandler.h代码。您能帮我吗?我添加了我需要的图片。好的,我可以实际上,我决定继续使用QLEVIEWCONTROLLER。现在,有没有一种方法可以自定义它?例如更改工具栏中的颜色?而不是使用白色?还有,我的最后一个问题,有没有一种方法可以自定义它,这样QLEVIEWCONTROLLER将具有与iBooks中类似的文本搜索功能?非常感谢您的帮助nswers。不,
QLPreviewController
是不可自定义的。您可以使用
UIWebView
来显示您感兴趣的文档,并围绕它构建所需的UI。它支持与Quick Look相同的文档类型。