Webview
委托shouldstartloadwithrequest
从 HTML 接收 url,当我检查请求时,所有内容都被转换为小写字母:
- (BOOL) webView: (UIWebView *) webView shouldStartLoadWithRequest:(NSURLRequest *) request navigationType: (UIWebViewNavigationType) navigationType {
// Only do something if a link has been clicked
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
NSString *link = [[request URL] absoluteString];
if ([link hasPrefix:@"playSound:"]) {
[PlayAudio playAudio: [link substringFromIndex:10]];
return NO;
}
}
return YES;
}
造成问题的线是
NSString *link = [[request URL] absoluteString];
在我获得点击链接的未修改副本之前。在 iOS3 和 iOS4 中它仍然是相同的。但在 iOS5 上,它只转换为小写。下一行
if ([link hasPrefix:@"playSound:"]) {
永远不会成为真的。所以我不得不将代码更改为
- (BOOL) webView: (UIWebView *) webView shouldStartLoadWithRequest:(NSURLRequest *) request navigationType: (UIWebViewNavigationType) navigationType {
// Only do something if a link has been clicked
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
NSString *link = [[[request URL] absoluteString] lowercaseString];
if ([link hasPrefix:@"playsound:"]) {
[PlayAudio playAudio: [link substringFromIndex:10]];
return NO;
}
}
return YES;
}