https://github.com/dmytriigolovanov/webkit-user-agent
Conveniently getting the User Agent through WKWebView
https://github.com/dmytriigolovanov/webkit-user-agent
cocoapods ios macos spm swift swiftpackagemanager useragent webkit wkwebview
Last synced: 2 months ago
JSON representation
Conveniently getting the User Agent through WKWebView
- Host: GitHub
- URL: https://github.com/dmytriigolovanov/webkit-user-agent
- Owner: dmytriigolovanov
- License: mit
- Created: 2021-12-03T16:30:13.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-11-14T12:01:34.000Z (over 3 years ago)
- Last Synced: 2025-06-19T17:50:46.943Z (12 months ago)
- Topics: cocoapods, ios, macos, spm, swift, swiftpackagemanager, useragent, webkit, wkwebview
- Language: Swift
- Homepage:
- Size: 44.9 KB
- Stars: 6
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# 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.
1. [CocoaPods](#cocoapods)
2. [Swift Package Manager](#swift-package-manager)
### CocoaPods
1. Prepare project for CocoaPods usage by [CocoaPods - Install / Get Started](https://cocoapods.org)
2. Add pod to project's profile
```ruby
pod 'WebKitUserAgent'
```
3. Install pod
```console
cd {PATH_TO_PROJECT}
pod install
```
### Swift Package Manager
1. Go to project
2. `File` → `Add Packages...`
3. Search for library, using URL:
```
https://github.com/dmytriigolovanov/webkit-user-agent
```
4. Set the `Dependency Rule` to `Up to Next Major Version`
5. `Add Package`
## Using
Import library to needed swift file.
```swift
import WebKitUserAgent
```
Library provides 3 variants of usage.
1. With prepared `WKWebView`.
**example:**
```swift
var webView: WKWebView
...
DispatchQueue.main.async {
let userAgent = webView.userAgent
}
}
```
2. With default `WKWebView`.
**example:**
```swift
WKUserAgent.fetchDefault { userAgent in
}
```
3. With `applicationName`.
Application name is additional part for User Agent, which will be added at the end of original WebView's User Agent.
Provided `overrideDefaultApplicationName` parameter for using/rewriting default `applicationName` from `WKWebViewConfiguration`.
(By default this parameter is `false`)
**example:**
```swift
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](https://github.com/dmytriigolovanov/webkit-user-agent/blob/main/LICENSE).