Sometimes we need to pass another user-agent when opening a URL in the WkWebView, so here how to do it in iOS app:
[_wkWebView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id result, NSError *error) {
NSString *version = [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleShortVersionString"];
NSString *userAgent = [result stringByAppendingFormat:@" %@/%@",@"Custom User Agent",version];
[self.wkWebView setCustomUserAgent: userAgent];
[self.wkWebView loadRequest:request];
}];
Top comments (0)