Giter VIP home page Giter VIP logo

kf99916 / progresswebviewcontroller Goto Github PK

View Code? Open in Web Editor NEW
80.0 10.0 25.0 790 KB

A webViewController implemented by WKWebView with a progress bar in the navigation bar

License: MIT License

Objective-C 1.30% Swift 94.85% Ruby 3.85%
wkwebview swift webview progress-bar self-signed-certificate bypass-ssl toolbar navigationbar in-app-browser webviewcontroller navigation cocoapods assigned-cookies blank-target

progresswebviewcontroller's Introduction

ProgressWebViewController

A WebViewController implemented by WKWebView with a progress bar in the navigation bar. The WebViewController is safari-like web browser.

CocoaPods GitHub stars GitHub forks CocoaPods Compatible Platform GitHub license

ProgressWebViewController ProgressWebViewController

Features

  • ✅ Progress bar in navigation bar
  • ✅ Bypass SSL according to the assigned hosts.( i.e., you can access the self-signed certificate websites with ProgressWebViewController)
  • ✅ Customize bar button items
  • ✅ Assign cookies to the web view
  • ✅ Browse the local html files
  • ✅ Support large titles for navigation bars in iOS 11
  • ✅ Support custom headers
  • ✅ Support custom user agent
  • ✅ Open the special urls including the app store, tel, mailto, sms, and _blank with other apps
  • ✅ Support the pull-to-refresh
  • ✅ Support the push navigation way

Requirements

  • iOS 12.0+

Installation

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

Once you have your Swift package set up, adding ProgressWebViewController as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/kf99916/ProgressWebViewController.git")
]

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate ProgressWebViewController into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'ProgressWebViewController'

Usage

Import

import ProgressWebViewController

Integration

ProgressWebViewController

A view controller with WKWebView and a progress bar in the navigation bar

var url: URL? the url to request
var tintColor: UIColor? the tint color for the progress bar, navigation bar, and tool bar
var delegate: ProgressWebViewControllerDelegate? the delegate for ProgressWebViewController
var scrollViewDelegate: ProgressWebViewControllerScrollViewDelegate? the delegate for scroll view var bypassedSSLHosts: [String]? the bypassed SSL hosts. The hosts must also be disabled in the App Transport Security.
var cookies: [HTTPCookie]? the assigned cookies
var headers: [String: String]? the custom headers
var userAgent: String? the custom user agent
var urlsHandledByApp: [String: Any] configure the urls handled by other apps (default [ "hosts": ["itunes.apple.com"], "schemes": ["tel", "mailto", "sms"], "_blank": true ])
var websiteTitleInNavigationBar = true show the website title in the navigation bar
var doneBarButtonItemPosition: NavigationBarPosition the position for the done bar button item. the done barbutton item is added automatically if the view controller is presented.(default .left)
var leftNavigaionBarItemTypes: [BarButtonItemType] configure the bar button items in the left navigation bar (default [])
var rightNavigaionBarItemTypes: [BarButtonItemType] configure the bar button items in the right navigation bar (default [])
var toolbarItemTypes: [BarButtonItemType] configure the bar button items in the toolbar of navigation controller (default [.back, .forward, .reload, .activity])
var navigationWay: [NavigationWay] configure the navigation way for clicking links (default .browser)
var pullToRefresh: Bool enable/disable the pull-to-refresh (default false)

Subclassing

You should set up the webview in loadView() and set up others in viewDidLoad()

class MyWebViewController: ProgressWebViewController {
    override open func loadView() {
        super.loadView()

        // set up webview, including cookies, headers, user agent, and so on.
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    // Other methods
}

ProgressWebViewControllerDelegate

The delegate for ProgressWebViwController

optional func progressWebViewController(_ controller: ProgressWebViewController, canDismiss url: URL) -> Bool
optional func progressWebViewController(_ controller: ProgressWebViewController, didStart url: URL)
optional func progressWebViewController(_ controller: ProgressWebViewController, didFinish url: URL)
optional func progressWebViewController(_ controller: ProgressWebViewController, didFail url: URL, withError error: Error)
optional func progressWebViewController(_ controller: ProgressWebViewController, decidePolicy url: URL) -> Bool optional func initPushedProgressWebViewController(url: URL) -> ProgressWebViewController

ProgressWebViewControllerScrollViewDelegate

The delegate for scroll view

optional func scrollViewDidScroll(_ scrollView: UIScrollView)

BarButtonItemType

The enum for bar button item

enum BarButtonItemType {
    case back
    case forward
    case reload
    case stop
    case activity
    case done
    case flexibleSpace
}

NavigationBarPosition

The enum for position of bar button item in the navigation bar

enum NavigationBarPosition {
    case none
    case left
    case right
}

NavigationWay

The enum for navigation way

enum NavigationWay {
    case browser
    case push
}

Apps using ProgressWebViewController

If you are using ProgressWebViewController in your app and want to be listed here, simply create a pull request.

I am always curious who is using my projects :)

Hikingbook - by Zheng-Xiang Ke

Hikingbook

Demo

ProgressWebViewControllerDemo is a simple demo app which browse the Apple website with ProgressWebViewController.

Author

Zheng-Xiang Ke, [email protected]

License

ProgressWebViewController is available under the MIT license. See the LICENSE file for more info.

progresswebviewcontroller's People

Contributors

bzhou392 avatar kf99916 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

progresswebviewcontroller's Issues

Xcode 15 Stored properties cannot be marked unavailable with '@available'

When we try to install the pod in Xcode 15, we are getting the error Stored properties cannot be marked unavailable with @available
in the following properties

@available(*, unavailable, renamed: "defaultURL") open var url: URL?
@available(iOS, obsoleted: 1.12.0, renamed: "defaultCookies") open var cookies: [HTTPCookie]?
@available(iOS, obsoleted: 1.12.0, renamed: "defaultHeaders") open var headers: [String: String]?

Screenshot 2023-09-21 at 12 52 03 Screenshot 2023-09-21 at 12 51 52 Screenshot 2023-09-21 at 12 50 42

How to make the back/forward button appear?

Hi,

Thanks for your lib. I'm facing a problem with add back/forward button to the toolbar.

  1. Init a navigation controller with root is ProgressWebViewController
  2. Set the navigationVC.isToolbarHidden = false
  3. Set .toolbarItemTypes = [.back, .forward, .reload, .activity]
  4. But only reload/activity button appear.

Can help on this?

User agent missing

Readme doc specifies a .userAgent property that is not available in the latest pod release

Back and forward buttons are not showing

im using this line but only reload and activity button are showing don't know why back and forward buttons are not showing

progressWebViewController.toolbarItemTypes = [.back, .forward, .reload, .activity]

Two Problems

  1. Bottom Bar Cannot display in iTouch7 14.4
  2. "Item" No any click event assign in storyboard

Crash on iPad when showing activity popover

It can be fixed as following

let activityViewController = UIActivityViewController(activityItems: [url], applicationActivities: nil)
activityViewController.popoverPresentationController?.barButtonItem = activityBarButtonItem
present(activityViewController, animated: true, completion: nil)

into activityDidClick()

need support open local html file

func load(_ url: URL) {
guard let webView = webView else {
return
}
if url.absoluteString.hasPrefix("http"){
let request = createRequest(url: url)
DispatchQueue.main.async {
webView.load(request)
}
}else{
webView.loadFileURL(url,allowingReadAccessTo:url)
}
}

没有判断NavigationBar是否存在的问题

因为顶部导航栏不是自定义的,是基于NavigationBar的;但是如果此页面从一个没有navigationController的页面present出来的话,就没有顶部的菜单按钮了。。。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.