Swiftpack.co - dmytriigolovanov/webkit-user-agent as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by dmytriigolovanov.
dmytriigolovanov/webkit-user-agent v2.0.1
Conveniently getting the User Agent through WKWebView
⭐️ 4
🕓 12 weeks ago
iOS macOS
.package(url: "https://github.com/dmytriigolovanov/webkit-user-agent.git", from: "v2.0.1")

WebKit User Agent

Requirements

  • iOS 9.0+
  • macOS 10.11+

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
    
    ... 
    
    WKUserAgent.fetch(fromWebView: webView) { result in 
        switch result {
        case .success(let userAgent):
            // Get the User Agent
        case .failure(let error):
            // Handle error
        }
    }
    
    // or
    
    webView.fetchUserAgent { result in
        switch result {
        case .success(let userAgent):
            // Get the User Agent
        case .failure(let error):
            // Handle error
        }
    }
  1. With default WKWebView.

example:

    WKUserAgent.fetch { result in 
        switch result {
        case .success(let userAgent):
            // Get the User Agent
        case .failure(let error):
            // Handle error
        }
    }
  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 rewriteDefaultApplicationName parameter for using/rewriting default applicationName from WKWebViewConfiguration.

example:

    let applicationName = "EXAMPLE/1.0.0"
    
    WKUserAgent.fetch(
        withApplicationName: applicationName, 
        rewriteDefaultApplicationName: true
    ) { result in 
        switch result {
        case .success(let userAgent):
            // Get the User Agent
        case .failure(let error):
            // Handle error
        }
    }

License

The contents of this repository are licensed under the MIT License.

GitHub

link
Stars: 4
Last commit: 3 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Release v2.0.1
12 weeks ago
  • Fixed iPad fix completion issue

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics