UIWebView - Scheme unknown
I need some help handling some NSData
object within an UIWebView
. Tapping a link inside UIWebView
cause a NSLog
entry:
Scheme unkown, doing nothing: <URL>
That is what I did:
I start an external HTTPGetOperation
to get a response of URL-request. I need to do so because of handling to download files. The response is stored to an NSData
object.
Then I load that data within a method that is called when HTTPGetOperation
is done:
[myWebView loadData:myNSDataObject MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@""]];
So far, UIWebView
shows the content of myNSDataObject
correctly.
But, when I 开发者_运维技巧try to tap a link inside that content I get a NSLog
entry "Unknown scheme, doing nothing: " with the URL of the link.
Notice: After tapping a link the delegate methods like -webView:shouldStartLoadWithRequest:navigationType:
are not called.
Notice: the delegate is set to [self.myWebView setDelegate:self]
Which methods creates that NSLog
entry?
Why are the delegate methods are not called after tapping a link?
Does anyone knows an answer?
How are the links coded? Are they http:// links or are they custom? As long as the link is in standard form, the shouldStartLoadWithRequest method can test the URL scheme to determine how it should be handled.
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0f, 44.0f, frame.size.width, frame.size.height - 44.0f)];
webView.delegate = self;
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if ([[[request URL] scheme] isEqualToString:@"mycustomdata"]) {
// insert your code here to actually load the correct data
return NO;
}
}
If your delegate isn't getting called, then you have some other issue. I would also recommend implementing didFailLoadWithError, webViewDidFinishLoad, and webViewDidStartLoad.
精彩评论