gpt4 book ai didi

ios - presentOpenInMenuFromRect 不工作 DocumentHandler.h - QuickLook

转载 作者:行者123 更新时间:2023-11-28 21:54:33 27 4
gpt4 key购买 nike

我正在使用 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

我需要帮助:(

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

enter image description here

最佳答案

presentOpenInMenuFromRect 是一个 UIDocumentInteractionController 方法。我不认为你在这段代码中使用了一个,除非你的 Root View Controller 是一个 UIDocumentInteractionController,这会非常非常奇怪。

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

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

关于ios - presentOpenInMenuFromRect 不工作 DocumentHandler.h - QuickLook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27028539/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com