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

Ios 如何从pdftron的webviewer中的tmp文件夹加载文档?,ios,objective-c,uiwebview,pdftron,Ios,Objective C,Uiwebview,Pdftron,我正在为iOS应用程序使用webviewer组件的HTML5 我已将“HTML5”文件夹添加为“为任何添加的文件夹创建文件夹引用”,并且“将项目复制到目标组的文件夹”未选中 iOS中给出的示例代码有一个名为“xod”的文件夹,其中包含一个默认文档,该文件夹被添加为“为任何添加的文件夹创建文件夹引用” 上述场景的示例中提到的代码如下所示: - (void)viewDidLoad { [super viewDidLoad]; UIWebView* webView = [[UIWebView a

我正在为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;
}
-(void)viewDidLoad
{
[超级视图下载];
UIWebView*webView=[[UIWebView alloc]initWithFrame:self.view.frame];
webView.delegate=self;
webView.autoresizingMask=uiviewsautoresizingflexiblewidth | uiviewsautoresizingflexiblewhight;
[self.view addSubview:webView];
NSString*fullPath=[[NSBundle mainBundle]pathForResource:@“/html5/MobileReaderControl”,类型:@“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加载请求:webviewerRequest];
}
-(BOOL)webView:(UIWebView*)webView应加载WithRequest:(NSURLRequest*)请求导航类型:(UIWebViewNavigationType)导航类型{
NSURL*URL=[请求URL];
如果([[URL方案]isEqualToString:@“iosrange”]){
NSString*requestString=[URL绝对字符串];
//取消协议
NSString*withoutProtocol=[[requestString组件由字符串分离:@/“]objectAtIndex:1];
NSArray*urlParts=[不包含由字符串分隔的协议组件:@“#”];
//文档位置是问号之前的所有内容
NSString*docPath=[[urlParts objectAtIndex:0]stringByDeletingPathExtension];
NSString*docLocation=[[NSBundle mainBundle]pathForResource:docPath的类型:@“xod”];
//查询字符串具有字节范围的开始值和可能的停止值
NSArray*queryString=[[urlParts objectAtIndex:1]由字符串分隔的组件:@“&”];
NSInteger rangeStart=[[queryString objectAtIndex:0]integerValue];
NSInteger originalRangeStart=rangeStart;
NSInteger rangeEnd=[[queryString objectAtIndex:1]integerValue];
NSFileHandle*fileHandle=[NSFileHandle fileHandleForReadingAtPath:docLocation];
如果(范围开始<0){
//负范围表示从文件末尾开始
//我们需要计算从文件开始的偏移量
NSInteger fileSize=[fileHandle seekToEndOfFile];
rangeStart=文件大小+rangeStart;
}
[fileHandle seekToFileOffset:rangeStart];
NSData*数据;
如果(rangeEnd==0){
数据=[fileHandle readDataToEndOfFile];
}否则{
数据=[fileHandle readDataOfLength:(rangeEnd-rangeStart)];
}
//将数据转换为base64
NSString*stringBuffer=[Utils encodeBase64WithData:data];
//使用数据调用JavaScript函数
//setTimeout用于确保它异步返回
NSString*jsFunction=[NSString stringWithFormat:@“setTimeout(function(){window.CoreControls.PartRetriever.IOSPartRetriever.PartSuccess('%@',%d);},0)”,stringBuffer,originalRangeStart];
[webView stringByEvaluatingJavaScriptFromString:jsFunction];
返回否;
}
返回YES;
}
但我的文档保存在应用程序的“tmp”文件夹中,因为它是从服务器下载的。我无法从tmp文件夹加载文档。请帮忙

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

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

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

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


提前感谢。

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

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

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