网址未在UIWebview中加载,#转换为%23

时间:2014-11-05 09:46:30

标签: ios objective-c uiwebview nsurl nsurlrequest

UIWebview 中加载以下本地路径网址。在spinepath中找到url,然后我转换为url [Spin​​ePathUrl]。

我的问题是,当我尝试加载时,我的价值为零。 为了检查目的,我将SpinepathUrl粘贴到浏览器中,显示未找到的网页。然后,我将SpinePathUrl " arugoswami-4.xhtml%23toc_marker-4" 更改为&# 34; arugoswami-4.xhtml#toc_marker-4" ,显示结果。

在网址中#是我的问题吗?当#从String转换为Url时,为什么#转换为%23。

spinepath = [NSString stringWithFormat:@"%@%@",documentsDirectory,Path];
spinepath = [spinepath stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
spinepath = [spinepath stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

[/ Users / blazedream / Library / Application Support / iPhone Simulator / 7.1 / Applications / E19D2CD0-E0DC-460E-8BC9-97A9C8010910 / Documents / UnzippedEpub / OEBPS / arugoswami-4.xhtml#toc_marker -4

NSURL *SpinePathUrl = [NSURL fileURLWithPath:spinepath];

[文件:///Users/blazedream/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/E19D2CD0-E0DC-460E-8BC9-97A9C8010910/Documents/UnzippedEpub/OEBPS/ arugoswami -4.xhtml%23toc_marker-4

NSURLRequest *request = [NSURLRequest requestWithURL:SpinePathUrl];
[webView loadRequest:request];

1 个答案:

答案 0 :(得分:3)

尝试手动添加片段

NSURL *baseUrl = [NSURL fileURLWithPath:@"... arugoswami-4.xhtml"];
NSURL *fullURL = [NSURL URLWithString:@"#toc_marker-4" relativeToURL:baseUrl];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:fullURL];

[myWebView loadRequest:urlRequest];