- Swift 5.3
- iOS 11.0+
- macOS 10.13+
See the subsections below for details about the different installation methods.
- Prepare project for CocoaPods usage by CocoaPods - Install / Get Started
- Add pod to project's profile
pod 'WebKitUserAgent'- Install pod
cd {PATH_TO_PROJECT}
pod install- Go to project
File→Add Packages...- Search for library, using URL:
https://github.com/dmytriigolovanov/webkit-user-agent
- Set the
Dependency RuletoUp to Next Major Version Add Package
Import library to needed swift file.
import WebKitUserAgentLibrary provides 3 variants of usage.
- With prepared
WKWebView.
example:
var webView: WKWebView
...
DispatchQueue.main.async {
let userAgent = webView.userAgent
}
}- With default
WKWebView.
example:
WKUserAgent.fetchDefault { userAgent in
}- With
applicationName. Application name is additional part for User Agent, which will be added at the end of original WebView's User Agent. ProvidedoverrideDefaultApplicationNameparameter for using/rewriting defaultapplicationNamefromWKWebViewConfiguration. (By default this parameter isfalse)
example:
let applicationName = "EXAMPLE/1.0.0"
WKUserAgent.fetch(
withApplicationName: applicationName,
overrideDefaultApplicationName: true
) { userAgent in
}The contents of this repository are licensed under the MIT License.