WebKitUserAgent

4.0.0

Conveniently getting the User Agent through WKWebView
dmytriigolovanov/webkit-user-agent

What's New

WebKitUserAgent v4.0.0

2022-11-14T12:02:07Z
  • Reorganized fetching logic & interface

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
  2. Swift Package Manager

CocoaPods

  1. Prepare project for CocoaPods usage by CocoaPods - Install / Get Started
  2. Add pod to project's profile
    pod 'WebKitUserAgent'
  1. Install pod
    cd {PATH_TO_PROJECT}
    pod install

Swift Package Manager

  1. Go to project
  2. FileAdd Packages...
  3. Search for library, using URL:
    https://github.com/dmytriigolovanov/webkit-user-agent
  1. Set the Dependency Rule to Up to Next Major Version
  2. Add Package

Using

Import library to needed swift file.

    import WebKitUserAgent

Library provides 3 variants of usage.

  1. With prepared WKWebView.

example:

    var webView: WKWebView
    
    ... 
    
    DispatchQueue.main.async {
        let userAgent = webView.userAgent
    }
}
  1. With default WKWebView.

example:

    WKUserAgent.fetchDefault { userAgent in
    
    }
  1. 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:

    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.

Description

  • Swift Tools 5.3.0
View More Packages from this Author

Dependencies

  • None
Last updated: Mon Jul 03 2023 08:27:53 GMT-0900 (Hawaii-Aleutian Daylight Time)