Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the “User-Agent” of a UIWebView in Swift3

I need to modify the useragent for some requests, and therefore I would either need to get it first, or append something to it. What's the best way of doing this? Do you have to use a webview to do it, or are there other ways?

what i trying :

var  userAgent = ""
    if UIWebView().stringByEvaluatingJavaScript(from: "navigator.userAgent") != nil{
        userAgent  =  userAgent  + " Custom-Agent"
    }
    print(userAgent)
    UserDefaults.standard.register(defaults: ["UserAgent" : userAgent])
like image 712
JDoe Avatar asked Jan 22 '26 02:01

JDoe


1 Answers

get user agent

var webView = UIWebView(frame: CGRect.zero)
var secretAgent: String? = webView.stringByEvaluatingJavaScript(from: "navigator.userAgent")

Change User-Agent

like image 80
Nazmul Hasan Avatar answered Jan 25 '26 19:01

Nazmul Hasan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!