WebKit User Agent
Requirements
- Swift 5.3
- iOS 11.0+
- macOS 10.13+
Installation
See the subsections below for details about the different installation methods.
CocoaPods
- 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
Swift Package Manager
- Go to project
File
→Add Packages...
- Search for library, using URL:
https://github.com/dmytriigolovanov/webkit-user-agent
- Set the
Dependency Rule
toUp to Next Major Version
Add Package
Using
Import library to needed swift file.
import WebKitUserAgent
Library 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. ProvidedoverrideDefaultApplicationName
parameter for using/rewriting defaultapplicationName
fromWKWebViewConfiguration
. (By default this parameter isfalse
)
example:
let applicationName = "EXAMPLE/1.0.0"
WKUserAgent.fetch(
withApplicationName: applicationName,
overrideDefaultApplicationName: true
) { userAgent in
}
License
The contents of this repository are licensed under the MIT License.