您的位置:首页 > 移动开发

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

2012-09-17 09:32 405 查看
UIWebView的使用这里不多说了,可参见/article/8082657.html

主要使用了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;
}


例子下载
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐