WEB开发网
开发学院手机开发iPhone 开发 iOS调用WebView私有API的方法 阅读

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

Tags:iOS 调用 WebView

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接