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

Viewed 4815

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])
1 Answers
Related