presentOpenInMenuFromRect不工作DocumentHandler.h – QuickLook

我正在使用documenthandler的cordova插件,如果我点击button,我得到的文档处理程序从PDF文件处理程序的工作正常,以便我可以将PDF保存到iBooks。

现在,而不是在查看器中打开文档,并单击共享button,然后再次单击以保存到iBooks我需要能够触发分享button,而无需打开文档。 我知道这可以使用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 

我需要帮助,请:(

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

在这里输入图像说明

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

实例化一个QLPreviewController实例化并呈现一个QLPreviewController ,并且显示与该文档图标相对应的rect的popup窗口。

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