美文网首页iOS
iOS客户端添加UserAgent

iOS客户端添加UserAgent

作者: 夏天爱大树 | 来源:发表于2017-04-07 17:16 被阅读15次

最近公司的项目需要用到WebView,WebView需要修改网页的布局(比如去掉某些不需要的header),需要添加UserAgent。上代码:

//一般写在appdelegate方法里
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
 
    //regist the new agent
    NSDictionary *dictionnary = [[NSDictionary alloc] initWithObjectsAndKeys:UA, @"UserAgent", nil];    
    [[NSUserDefaults standardUserDefaults] registerDefaults:dictionnary];
    return YES;
}

具体原理我也不是很清楚,如果有知道的请告诉我,谢谢!

相关文章

网友评论

    本文标题:iOS客户端添加UserAgent

    本文链接:https://www.haomeiwen.com/subject/znwhattx.html