Coder Social home page Coder Social logo

swiftwebvc's Introduction

SwiftWebVC

SwiftWebVC is a simple inline browser for your Swift iOS app.

SwiftWebVC

SwiftWebVC features:

  • iPhone and iPad distinct UIs
  • Full landscape orientation support
  • Back, forward, stop/refresh and share buttons
  • Open in Safari and Chrome UIActivities
  • Navbar title set to the currently visible web page
  • Talks with setNetworkActivityIndicatorVisible
  • 3 different themes to choose from when presented modally

SwiftWebVC

Installation

CocoaPods

  • SwiftWebVC is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'SwiftWebVC'

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate SwiftWebVC into your Xcode project using Carthage, specify it in your Cartfile:

github "meismyles/SwiftWebVC"

Run carthage update to build the framework and drag the built SwiftWebVC.framework into your Xcode project.

Manual

  • Add the SwiftWebVC/ folder into your project.

Usage

Just like any UIViewController, SwiftWebVC can be pushed into a UINavigationController stack:

let webVC = SwiftWebVC(urlString: "http://google.com")
self.navigationController?.pushViewController(webVC, animated: true)

It can be presented modally using SwiftModalWebVC:

let webVC = SwiftModalWebVC(urlString: "http://google.com")
self.present(webVC, animated: true, completion: nil)

Options

The share button can be disabled by passing a flag in to the constructor to specify this:

let webVC = SwiftWebVC(urlString: "http://google.com", sharingEnabled: false)

The same principal applies for the modal implementation also:

let webVC = SwiftModalWebVC(urlString: "http://google.com", sharingEnabled: false)

Modal Options Only

Themes may be chosen for the modal implementation. The default theme is Light-Blue. Other modal themes Light-Black and Dark may be chosen using one of the following instead:

let webVC = SwiftModalWebVC(urlString: "http://google.com", theme: .lightBlack)
let webVC = SwiftModalWebVC(urlString: "http://google.com", theme: .dark)

Delegate (Start/Finish Loading Callbacks)

SwiftWebVC also includes a delegate protocol that allows you to implement didStartLoading and didFinishLoading functions to determine when loading starts and finishes.

Note: This is currently only implemented for SwiftWebVC, not SwiftModalWebVC.

To implement this, after declaring your instance of SwiftWebVC, set it's delegate and implement the callback functions. For example:

Inititalisation

let webVC = SwiftWebVC(urlString: "https://www.google.com")
webVC.delegate = self
self.navigationController?.pushViewController(webVC, animated: true)

Delegate Implementation

extension ViewController: SwiftWebVCDelegate {
    
    func didStartLoading() {
        print("Started loading.")
    }
    
    func didFinishLoading(success: Bool) {
        print("Finished loading. Success: \(success).")
    }
}

SwiftWebVCActivity

Starting in iOS 6 Apple uses UIActivity to let you show additional sharing methods in share sheets. SwiftWebVC comes with "Open in Safari" and "Open in Chrome" activities. You can easily add your own activity by subclassing SwiftWebVCActivity which takes care of a few things automatically for you. Have a look at the Safari and Chrome activities for implementation examples.Typed

Credits

SwiftWebVC is a Swift implementation of Sam Vermette's SVWebViewController. Code transcription, updates and changes were carried out by Myles Ringle. The original SVWebViewController was brought to you by Sam Vermette and contributors to the project.

If you have feature suggestions or bug reports, feel free to help out by sending pull requests or by creating new issues. If you're using SwiftWebVC in your project, attribution is always appreciated.

Thanks to Icons8 for the images.

swiftwebvc's People

Contributors

alroman avatar antigp avatar azhararmar avatar bchrobot avatar igorkulman avatar jalakoo avatar lfarah avatar meismyles avatar mwilliams123 avatar ntnhon 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  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

swiftwebvc's Issues

Navigation Bar Items Wrong Position on First Load

I'm having an issue in iOS 11 where when you first open the view controller the back, forward, refresh and share buttons are all in the wrong place.

1

They should be in the following position even before the page loads.

2

@3x Images are missing.

Also, you don't need to create Ipad specific images. You can check iPhone and iPad from attributes inspector

SwiftWebVC never loads some urls, Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service

Trying SwiftWebVC out for the first time and I'm having a problem loading certain pages. This is how I show it:

let webVC = SwiftWebVC(urlString: "http://www.udwa.org/our-union/")
webVC.delegate = self
self.navigationController?.pushViewController(webVC, animated: true)

The delegate call back tells me that it started loading, after 30 seconds I get the following in the console:

2017-10-14 11:57:05.941522-0700 udw[61741:29492827] Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service
2017-10-14 11:57:05.942308-0700 udw[61741:29492827] Could not signal service com.apple.WebKit.Networking: 113: Could not find specified service

I tried several other URLs:

  1. https://www.google.com/ : worked, doesn't print the WebContent error above
  2. https://github.com/meismyles/SwiftWebVC : worked, doesn't print the WebContent error above
  3. http://www.inadaydevelopment.com : failed. This is my company's website, a WP site hosted in Google's cloud.
  4. http://herdboss.com/ : failed. This is another company I'm part of, a drupal site hosted at Rackspace.
  5. http://garyjohnston.com/ : failed. A friend's website, a WP site. Not sure where it's hosted, but it's a different server from 3 and 4 above.

I get the same behavior when using the SwiftModalWebVC.

Any help is appreciated.

screen shot 2017-10-14 at 11 48 30 am

Image assets for buttons aren't loaded

Hi, I've tried adding SwiftWebVC to an empty project via CocoaPods but there is an issue with image assets in the bundle. It looks like once the pod is installed, image assets are not a part of the bundle anymore (although if you look on the filesystem, they are). The result is that the images aren't loaded when the browser view is displayed. Attached screenshot shows the issue.

If you need more information, please let me know.

swiftwebvc-issue

Force-unwrapping URL leads to crash, if the url string is invalid.

public convenience init(urlString: String) {
        var urlString = urlString
        if !urlString.hasPrefix("https://") && !urlString.hasPrefix("http://") {
            urlString = "https://"+urlString
        }
        self.init(pageURL: URL(string: urlString)!)
 }

when urlString is invalid, URL(string: urlString) is nil - that leads to crash.

Title not centered

Seems like the title of subpages is not always centered. If I open the viewController as follows and navigate back and forth in the pages, sometimes the title is aligned left, instead of center (see screenshot below: Kontakte title in bar on top).

UINavigationController(rootViewController: SwiftWebVC(urlString: "https://mandelkind.help/valletti"))

simulator screen shot 26 06 2017 21 12 53

Crash on iOS11

On iOS11 showing the browser crashes in SwiftWebVC.swift in method updateToolbarItems() on

let refreshStopBarButtonItem: UIBarButtonItem = webView.isLoading ? stopBarButtonItem : refreshBarButtonItem

with Thread 1: EXC_BAD_ACCESS (code=2, address=0x604000286f90) when the browser is first opened.

Dismiss button on `SwiftModalWebVC`

Hey @meismyles

I've noticed that the modal version of the browser uses a V icon for dismissing the modal view instead of the more traditional and well-established X.

Is this something that you could change or at least make configurable?

Crash while navigating in and then back out again quickly

When pushing SwiftWebVC on the navigation controller and pressing back again before loading, it can cause SwiftWebVC to crash due to forced unwrapped optionals.

Solution:
from line 197 in SwiftWebVC.swift
replace

            if !closing {
                if presentingViewController == nil {
                    navigationController!.toolbar.barTintColor = navigationController!.navigationBar.barTintColor
                }
                else {
                    navigationController!.toolbar.barStyle = navigationController!.navigationBar.barStyle
                }
                navigationController!.toolbar.tintColor = navigationController!.navigationBar.tintColor
                toolbarItems = items as? [UIBarButtonItem]
            }

with

            if let navigationController = navigationController, !closing {
                if presentingViewController == nil {
                    navigationController.toolbar.barTintColor = navigationController.navigationBar.barTintColor
                }
                else {
                    navigationController.toolbar.barStyle = navigationController.navigationBar.barStyle
                }
                navigationController.toolbar.tintColor = navigationController.navigationBar.tintColor
                toolbarItems = items as? [UIBarButtonItem]
            }

Xcode doesn't recognise the SwiftWebVC class

Whenever I try to instantiate the SwiftWebVC or any other class I get a compiler error that it isn't recognized.
Even tough the assets are recognized.

Am I missing something, is this a known issue because this currently renders the the whole framework unusable for me.

screen shot 2018-06-21 at 12 43 35

High Memory Usage

I've been on/off with SwiftWebVC because it used up A LOT of storage. Haven't specifically found anything yet, so decided to post this issue up.

iOS 8 support

I have tried running in Simulator iOS 8.1 and everything is working well except #22

I think you could change deployment target to 8 in the podspec

Blank screen with activity indicator issue for certain URL strings cases

Version: 0.4.0

I noticed there are two cases where your module gets stuck on a blank screen with a spinning Activity Indicator (see screenshot):

simulator screen shot jun 12 2017 5 15 43 pm

  1. No schema
let webVC = SwiftModalWebVC(urlString: "www.google.com")
  1. HTTP schema (not HTTPS)
let webVC = SwiftModalWebVC(urlString: "http://www.google.com")

I'm able to make this work if you create an iOS 8+ ATS exception for each HTTP domain or if you set NSAllowsArbitraryLoads.

	<key>NSAppTransportSecurity</key>
	<dict>
		<key>NSAllowsArbitraryLoads</key>
		<true/>
	</dict>

My question is: is there any way to allow HTTP links on WKWebView without doing the above?

Thanks!

Swift 4

Hi, are you considering update it to support swift 4?

Thanks

Crash while using inside UIPagerViewController

When using your module inside UIPagerViewController app will crash. It happening because deinit method accessing lazy var that not initialized yet. So lazy var perform init and try to set deallocating object as delegate to WKWebView.
UIPagerViewController requires two VC (in case when pager view displays only one VC at time), one of them will be unused and deallocated before loadView() was called.

Add some delegate methods

Like didStartLoading, didFinishLoading, didFailLoading

This way we can show a progress while loading

Can I use this Pod in swift 4.2 or later versions?

I have installed this pod for swift 4.2.
It causes some errors while compiling. So I unlocked the Podfiles and fixed it for swift4.2.
But, the problem is, the 'Done' Button isn't appear.
I found this pod for that point. To back my app.
Can you explain more about it or provide any updated versions of this Pod?

Dismissing SwiftModalWebVC does not stop webview

For example, if you are playing audio in a modal web VC and dismiss it the audio continues playing.

I believe this is due to the doneButtonTapped method being handled by the child webViewController: SwiftWebVC

Inject JavaScript

Hi thanks for the great code! I am trying to find a way to inject JavaScript to the embedded WebView. Could anyone shed some lights here? Thanks!

Crash in iOS 11

crash log:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Completion handler passed to -[SwiftWebVC.SwiftWebVC webView:decidePolicyForNavigationAction:decisionHandler:] was called more than once'
*** First throw call stack:
(0x18606c4e8 0x1a89dc528 0x18606c430 0x18e3538c0 0x18e3996f4 0x1095fc0f0 0x1095fbf1c 0x1095fc0b0 0x18e397258 0x18e4f9fcc 0x18e522c78 0x18e51c32c 0x18e394bdc 0x18e56ee50 0x18e356440 0x18e353db8 0x18e356670 0x18942c178 0x18942c438 0x1860131a0 0x1860129d4 0x18601057c 0x185f2b03c 0x19679ef94 0x18cef086c 0x1042d4030 0x1a974bd1c)
libc++abi.dylib: terminating with uncaught exception of type NSException

Not compiling in XCode 9.2

When trying to compile the framework this error arrises:

SwiftWebVC/SwiftWebVC/SwiftWebVC.swift:133:75: Cannot assign value of type 'UIColor?' to type 'UIColor!'

Doesn't display local files properly

When trying to display a local file like this url: "file:///var/mobile/Containers/Data/Application/blahblahblah/downloads/15212173031370-A8AB82E7-A719-4148-89CE-D5CE9FD468C6.jpg" it doesn't display anything. This is related to an old WKWebView bug that has since been fixed back in iOS 9.
It requires that we load the url with
webView.loadFileURL(url, allowingReadAccessTo: url)
instead of
webView.load(request)

I've managed to find a spot to drop that in that works, but is a little ugly and probably doesn't match the organization of the existing code very well.

If you drop the following code in right here it fixes things.

func loadRequest(_ request: URLRequest) {
        if let url = request.url,
            url.absoluteString.contains("file:"),
            #available(iOS 9.0, *) {
                webView.loadFileURL(url, allowingReadAccessTo: url)
        } else {
            webView.load(request)
        }
}

Using this library from Objc?

Hello and thank you for this library! I have a project with both Swift and legacy Objective C ViewControllers and I am trying to use this library from my objc classes but I cannot call the initializers.

From swift it works fine and its great. :) Any plans on adding obj c support? (Since this library uses the WKWebView while the objc library this is based on uses the deprecated UIWebView)

Alter the HTML loaded in SwiftWebVC?

Is there any way to insert myself into the html loading process? I'd like to apply a few simple text replacements with the html, but the delegate only gives me start and finish call backs.

Is the only way to wait until it has been loaded and then pull the HTML from the webview, change it, and then set it? If so, will that trigger the didFinishLoading() callback again?

Done button not appearing

I am using below code,

let webVC = SwiftWebVC(urlString: "http://google.com")
self.navigationController?.pushViewController(webVC, animated: true)

But I don't see Done button on top.

This is the most important part of this lib and its missing.

** You have this functionality in Modal.

handle js

in SwiftWebVC.swift, i have added config as follw

public class SwiftWebVC: UIViewController,WKScriptMessageHandler {
public var jsHandler:((WKScriptMessage)->())?
...
}
lazy var webView: WKWebView = {
        let configuration = WKWebViewConfiguration()
        configuration.userContentController.add(self, name: "wawa")
        var tempWebView = WKWebView(frame: UIScreen.main.bounds, configuration: configuration)
        tempWebView.uiDelegate = self
        tempWebView.navigationDelegate = self
        return tempWebView;
    }()
public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
        if self.jsHandler != nil {
            self.jsHandler!(message)
        }
    }

and it just fail to work, maybe i need help.

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.