-1

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;
}
4

2 回答 2

1

这是作为 iOS 5 中 safari 升级的一部分所做的更改,并且与 URL 的规范一致。URL 方案将始终转换为小写。

(由于这个变化,我不得不修复很多代码)

于 2013-07-08T12:22:53.547 回答
0
if ([link hasPrefix:@"playsound:"] ||[link hasPrefix:@"playSound:"] )
{
    [PlayAudio playAudio: [link substringFromIndex:10]];
        return NO;
}
于 2013-07-08T12:19:06.927 回答