Otafuku provides utility classes to use WKWebView in Swift.

Related tags

Web View Otafuku
Overview

Otafuku

Language CocoaPods License Issues

Otafuku provides utility classes to use WKWebView.

Features

  • WebViewUIController to handle WKUIDelegate methods by presenting an alert as usual browsers do.
  • WebViewPropertyObserver to notify WKWebView property value change via a registered closure and Swift enum. With this class, no KVO code is needed to know WKWebView property value change.

Usage

WebViewUIController

WebViewUIController handles WKUIDelegate.
As shown below, simply declare a property of WebViewUIController and set it to WKWebView.UIDelegate in UIViewController.viewDidLoad.

class ViewController: UIViewController {
    let uiDelegate = WebViewUIController()

    override func viewDidLoad() {
        super.viewDidLoad()
        webView.UIDelegate = uiDelegate
    }
}

WebViewPropertyObserver

WebViewPropertyObserver notifies WKWebView property value change.
As shown below, declare a property of WebViewPropertyObserver to retain its object throughout the ViewController's life cycle.
To initialize, pass a WKWebView object and a closure handling WKWebView's property change.

class ViewController: UIViewController {
    @IBOutlet var progressView: UIProgressView!
    @IBOutlet var backItem: UIBarButtonItem!
    @IBOutlet var forwardItem: UIBarButtonItem!

    var propertyObserver: WebViewPropertyObserver?

    override func viewDidLoad() {
        super.viewDidLoad()
        propertyObserver = WebViewPropertyObserver(webView: webView, handler:handleWebViewPropertyChange)
    }

    func handleWebViewPropertyChange(property: WebViewPropertyObserver.WebViewProperty) {
        switch property {
        case .Title(let title):
            navigationItem.title = title
        case .URL(let URL):
            // do something with URL
            break
        case .CanGoBack(let canGoBack):
            backItem.enabled = canGoBack
        case .CanGoForward(let canGoForward):
            forwardItem.enabled = canGoForward
        case .EstimatedProgress(let progress):
            progressView.progress = progress
        case .Loading(let loading):
            // do something with loading
            break
        case .HasOnlySecureContent(let secureContent):
            // do something with secureContent
            break
        }
    }
}

Requirements

  • iOS 8.0+
  • Swift 3.0
  • Xcode 8.0

Installation

  • Install with CocoaPods
platform :ios, '8.0'
use_frameworks!

pod 'Otafuku'

License

Otafuku is released under the MIT license. See LICENSE for details.

You might also like...
WKWebView handling popup windows

WKWebViewWithPopUp WKWebView handling pop-up windows Property If there is a pop-up window, use the pop-up window. If there is no pop-up window, use th

Proof-of-concept `WKWebview.evaluateJavaScript(...)` replacement for WebSocket-based Javascript execution.

Proof-of-concept `WKWebview.evaluateJavaScript(...)` replacement for WebSocket-based Javascript execution.

Conveniently getting the User Agent through WKWebView

WebKit User Agent Requirements iOS 9.0+ macOS 10.11+ Installation See the subsec

WebViewCustomFont - WKWebView extension to addScript for inject a custom font-face
WebViewCustomFont - WKWebView extension to addScript for inject a custom font-face

WebViewCustomFont WKWebView extension to addScript for inject a custom font-face

How to handle HelaPay links inside UIWebView and WKWebView

Handling හෙළPay Links Setup Clone this repo. git clone https://github.com/PayHereDevs/helapay-link-handler.git To properly handle හෙළPay Links in you

Modern JavaScriptBridge for JSContext & WKWebview.
Modern JavaScriptBridge for JSContext & WKWebview.

HWJavaScriptBridge Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements iOS 6.0+ Ins

OysterKit is a framework that provides a native Swift scanning, lexical analysis, and parsing capabilities. In addition it provides a language that can be used to rapidly define the rules used by OysterKit called STLR

OysterKit A Swift Framework for Tokenizing, Parsing, and Interpreting Languages OysterKit enables native Swift scanning, lexical analysis, and parsing

Provides a custom presentation modifier that provides more options including full screen presentations. (iOS)

Presentation Also available as a part of my SwiftUI+ Collection – just add it to Xcode 13+ Provides a custom presentation modifier that provides more

BFKit-Swift is a collection of useful classes, structs and extensions to develop Apps faster.
BFKit-Swift is a collection of useful classes, structs and extensions to develop Apps faster.

Features • Classes and Extensions Compatibility • Requirements • Communication • Contributing • Installing and Usage • Documentation • Changelog • Exa

How Swift standard types and classes were supposed to work.
How Swift standard types and classes were supposed to work.

How Swift standard types and classes were supposed to work. A collection of useful extensions for the Swift Standard Library, Foundation, and UIKit.

Extensions and classes in Swift that make it easy to get an iOS device reading and processing MIDI data

MorkAndMIDI A really thin Swift layer on top of CoreMIDI that opens a virtual MIDI destination and port and connects to any MIDI endpoints that appear

SwiftColorArt is a demo application that includes Swift files with all classes and extension necessary to create a font color schema matching to an image
SwiftColorArt is a demo application that includes Swift files with all classes and extension necessary to create a font color schema matching to an image

SwiftColorArt SwiftColorArt is a demo application that includes Swift files with all classes and extension necessary to create a font color schema mat

A protocol to serialize Swift structs and classes for encoding and decoding.
A protocol to serialize Swift structs and classes for encoding and decoding.

Serpent (previously known as Serializable) is a framework made for creating model objects or structs that can be easily serialized and deserialized fr

Key-Value Coding (KVC) for native Swift classes and structs

SwiftKVC SwiftKVC brings key-value coding to native Swift classes and structures. You can easily set and access properties just using a subscript: var

A set of helper classes and functions in Swift

SwiftTools This is a set of tools written in Swift that add some sugar and some small functionality. Mainly meant for small projects and scripts, as a

Extensions for Swift Standard Types and Classes

Cent Cent is a library that extends certain Swift object types using the extension feature and gives its two cents to Swift language. Dollar is a Swif

Classes-and-structures-in-swift - This source files show what is the difference between class and structure

This source files show what is the difference between class and structure You ca

Adding ruby style each iterator to Cocoa/Cocoa touch Swift Array and Range classes, And Int.times{} to Int class

Collection-Each Adding ruby style each iterator to Cocoa/Cocoa touch Swift Array, Dictionary and Range classes, and Int.times ###Why? Array/Dictionary

Releases(1.1.0)
Owner
Kazunobu Tasaka
Kazunobu Tasaka
A drop-in inline browser for your Swift iOS app.

SwiftWebVC SwiftWebVC is a simple inline browser for your Swift iOS app. SwiftWebVC features: iPhone and iPad distinct UIs Full landscape orientation

Myles Ringle 314 Dec 22, 2022
iOS utility classes for asynchronous rendering and display.

YYAsyncLayer iOS utility classes for asynchronous rendering and display. (It was used by YYText) Simple Usage @interface YYLabel : UIView @property NS

null 672 Dec 27, 2022
JSONExport is a desktop application for Mac OS X which enables you to export JSON objects as model classes with their associated constructors, utility methods, setters and getters in your favorite language.

JSONExport JSONExport is a desktop application for Mac OS X written in Swift. Using JSONExport you will be able to: Convert any valid JSON object to a

Ahmed Ali 4.7k Dec 30, 2022
MarkdownView is a WKWebView based UI element, and internally use bootstrap, highlight.js, markdown-it.

MarkdownView is a WKWebView based UI element, and internally use bootstrap, highlight.js, markdown-it.

Keita Oouchi 1.8k Dec 21, 2022
A small package that provides a Swift API for instantiating Swift and Objective-C classes by their non-namespaced class name.

Reflection A small package that provides a Swift API for instantiating Swift and Objective-C classes by their non-namespaced class name. Installation

Kelly Dun 0 Apr 10, 2022
The Waterwheel Swift SDK provides classes to natively connect iOS, macOS, tvOS, and watchOS applications to Drupal 7 and 8.

Waterwheel Swift SDK for Drupal Waterwheel makes using Drupal as a backend with iOS, macOS, tvOS, or watchOS enjoyable by combining the most used feat

Kyle Browning 414 Jul 26, 2022
OSCKit - The OSCKit package provides the classes needed for your apps to communicate among computers, sound synthesizers

OSCKit The OSCKit package provides the classes needed for your apps to communica

Sammy Smallman 23 Nov 27, 2022
Swift-Misc-Utility - Taking the misc out of General Utility so that General only defines the namespace

Swift-Misc-Utility Everything extra that used to be in Swift-General-Utility has

Erica Sadun 4 Feb 4, 2022
Swift library for embedding and controlling YouTube videos in your iOS applications via WKWebView!

YouTubePlayer Embed and control YouTube videos in your iOS applications! Neato, right? Let's see how it works. 0.7.0 Update: WKWebView breaking change

Giles Van Gruisen 825 Jan 3, 2023
A Swift event bus for UIWebView/WKWebView and JS.

An event bus for sending messages between UIWebView/WKWebView and embedded JS. Made with pure Swift. Features Easy, fast and reliable event bus system

Coshx 149 Oct 9, 2022