iOS调用WebView私有API的方法
2013-06-14 20:27:46 来源:WEB开发网核心提示:- (void)modifyUA{ id webView = [uiWebViewInstance valueForKeyPath:@"_internal.browserView._webView"]; [webView performSelector:@selector(setCust
- (void)modifyUA { id webView = [uiWebViewInstance valueForKeyPath:@"_internal.browserView._webView"]; [webView performSelector:@selector(setCustomUserAgent:) withObject:@"Mozilla/5.0 (Windows; U; Windows NT 5.2) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13 "]; }
这是示例修改User Agent。获取WebView使用的是Key-Value Coding的方法
为了更安全地通过apple的审查,可以这样:
- (void)modifyUA { NSString *path = [@"_internal.browser" stringByAppendingString:@"View._webView"]; id webView = [g_webView valueForKeyPath:path]; NSString *selString = [@"setCustom" stringByAppendingString:@"UserAgent:"]; SEL sel = NSSelectorFromString(selString); [webView performSelector:sel withObject:@"Mozilla/5.0 (Windows; U; Windows NT 5.2) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13 "]; }
把字符串分割再合成就ok
出处:http://blog.csdn.net/hursing
更多精彩
赞助商链接