2
votes

Stucked on load the below Local path url in UIWebview. Find the url in spinepath, then i converted to url [SpinePathUrl].

My issue is, when i try to load,i'm getting nil value. For checking purpose, i pasted the SpinepathUrl into browser it show webpage not found.Then, i changed SpinePathUrl "arugoswami-4.xhtml%23toc_marker-4" into "arugoswami-4.xhtml#toc_marker-4", its showed result.

Is the # is my issue in url.? Why the # converted to %23, when it converting from String to Url.

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];

[file:///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
Please clear your questiongran33
you didnot understand?/Ramdhas
No mate, can u please mark the question and the problem?gran33
# getting convert to %23, do you know why??Ramdhas
yes. The # char isn't legal in a valid url. You should encode that to %23gran33

1 Answers

3
votes

Try adding fragment manually

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

[myWebView loadRequest:urlRequest];