解析自定义头像、链接、处理微博上类似 “@” 和 “#” 的特殊转义字符并在UIWebView显示的例子

来源:互联网 发布:淘宝买亚马逊礼品卡 编辑:程序博客网 时间:2024/06/05 07:10

UIWebView的使用这里不多说了,可参见http://blog.csdn.net/iunion/article/details/7963291


主要使用了RegexKitLite正则类库分析替换数据

链接操作使用:

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {     NSLog(@"shouldStartLoadWithRequest");        BOOL result = YES;    NSURL *requestURL = [request URL];    NSString *requestString = [[request URL] absoluteString];    NSLog(@"URL: %@", requestString);        NSString *schemeStr = [requestURL scheme];    if ( ([schemeStr isEqualToString:@"http"] || [schemeStr isEqualToString:@"https"] || [schemeStr isEqualToString:@"mailto"] || [schemeStr isEqualToString:@"tel"])        && (navigationType == UIWebViewNavigationTypeLinkClicked) )    {        result = ![[UIApplication sharedApplication] openURL:requestURL];    }    else if ([schemeStr isEqualToString:@"wixun"])    {        NSString *host = [requestURL host];                if ([host isEqualToString:@"user"])        {            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[[requestURL queryArgumentForKey:@"username"] URLDecodedString] message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];            [alert show];                        return NO;        }    }        return result;}

例子下载

原创粉丝点击