iOS设置UIWebView的User-Agent

在didFinishLaunchingWithOptions方法中设置UIWebView的User-Agent,这样可以搭配HTML实现原生与网页的交互

    UIWebView* tempWebView = [[UIWebView alloc] initWithFrame:CGRectZero];
    NSString* userAgent = [tempWebView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
    NSString *ua = [NSString stringWithFormat:@"%@\\%@",
                    userAgent,
                    @"YourAgent"];
    [[NSUserDefaults standardUserDefaults] registerDefaults:@{@"UserAgent" : ua, @"User-Agent" : ua}];

你可能感兴趣的:(iOS设置UIWebView的User-Agent)