gpt4 book ai didi

ios - 如何从 pdftron 的 webviewer 中的 tmp 文件夹加载文档?

转载 作者:行者123 更新时间:2023-11-29 10:43:08 25 4
gpt4 key购买 nike

我正在为 iOS 应用程序使用 webviewer 组件的 HTML5。

我已将“HTML5”文件夹添加为“为任何添加的文件夹创建文件夹引用”并且未选中“将项目复制到目标组的文件夹”。

iOS 中给出的示例代码有一个名为“xod”的文件夹和一个默认文档,该文件夹被添加为“为任何添加的文件夹创建文件夹引用”。

上述场景示例中提到的代码如下:

- (void)viewDidLoad
{
[super viewDidLoad];

UIWebView* webView = [[UIWebView alloc] initWithFrame:self.view.frame];

webView.delegate = self;
webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

[self.view addSubview:webView];

NSString* fullPath = [[NSBundle mainBundle] pathForResource:@"/html5/MobileReaderControl" ofType:@"html"];

NSURL *url = [NSURL fileURLWithPath:fullPath];
NSString* absoluteString = [url absoluteString];
NSString* stringWithQuery = [absoluteString stringByAppendingString:@"#d=iosrange://xod/GettingStarted.xod"];
NSURL* webviewUrl = [NSURL URLWithString:stringWithQuery];

NSURLRequest* webviewerRequest = [[NSURLRequest alloc] initWithURL:webviewUrl];
[webView loadRequest:webviewerRequest];
}

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *URL = [request URL];

if ([[URL scheme] isEqualToString:@"iosrange"]) {
NSString *requestString = [URL absoluteString];
// get rid of the protocol
NSString *withoutProtocol = [[requestString componentsSeparatedByString:@"//"] objectAtIndex:1];

NSArray *urlParts = [withoutProtocol componentsSeparatedByString:@"#"];
// document location is everything before the question mark
NSString *docPath = [[urlParts objectAtIndex:0] stringByDeletingPathExtension];
NSString *docLocation = [[NSBundle mainBundle] pathForResource:docPath ofType:@"xod"];

// query string has start and possibly stop values for the byte range
NSArray *queryString = [[urlParts objectAtIndex:1] componentsSeparatedByString:@"&"];
NSInteger rangeStart = [[queryString objectAtIndex:0] integerValue];
NSInteger originalRangeStart = rangeStart;
NSInteger rangeEnd = [[queryString objectAtIndex:1] integerValue];

NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:docLocation];
if (rangeStart < 0) {
// a negative range means it's from the end of the file
// we need to calculate what that offset is from the beginning of the file
NSInteger fileSize = [fileHandle seekToEndOfFile];
rangeStart = fileSize + rangeStart;
}

[fileHandle seekToFileOffset:rangeStart];

NSData *data;
if (rangeEnd == 0) {
data = [fileHandle readDataToEndOfFile];
} else {
data = [fileHandle readDataOfLength:(rangeEnd - rangeStart)];
}

// convert data to base64
NSString *stringBuffer = [Utils encodeBase64WithData:data];

// call JavaScript function with the data
// setTimeout is used to make sure that it returns asynchronously
NSString *jsFunction = [NSString stringWithFormat:@"setTimeout(function() {window.CoreControls.PartRetrievers.IOSPartRetriever.PartSuccess('%@', %d);}, 0)", stringBuffer, originalRangeStart];
[webView stringByEvaluatingJavaScriptFromString:jsFunction];

return NO;
}
return YES;
}

但是我的文档保存在应用程序的“tmp”文件夹中,因为它是从服务器下载的。而且我无法从 tmp 文件夹加载文档。请帮忙。

我无法将文档从“tmp”文件夹移动到“xod”,因为我无法在运行时更改 Bundle,而且该文档也在其他地方使用。

当我在 bundle 的“xod”文件夹中添加文档时,它会加载罚款。但是当我尝试从应用程序中的“tmp”文件夹加载文档时,它不会加载。我尝试在“stringWithQuery”中附加文档的路径,但没有成功。

主要问题是“stringWithQuery”。请帮忙。

我想从“tmp”文件夹加载文档。

提前致谢。

最佳答案

问题似乎是编写了示例代码以从应用程序包中读取 .xod 文件,但您正在将 xod 文件下载到临时目录。所以你需要改变

NSString* fullPath = [[NSBundle mainBundle] pathForResource:docPath ofType:@"xod"];

NSString* fullPath = [[NSTemporaryDirectory() stringByAppendingPathComponent:docPath] stringByAppendingPathExtension:@"xod"];

关于ios - 如何从 pdftron 的 webviewer 中的 tmp 文件夹加载文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23486133/

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