Skip to content

dmandarino/CSafariWebKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CSafariWebKit

A framework to browser web from your app and easily configured it.

Overview

It works as a wrapper for SFSafariViewController and WKWebView that helps with customizations, takes away the need to implement delegates and uncovers the intelligence of browsing the web from inside of your app.

Getting Started

Prerequisites

Your app's target should be at least iOS 11.0. And if you are not cloning it, then you will need CocoaPods.

Installing

You can either clone it and add it as a Framework or you can use it as a dependency from CocoaPods

CocoaPods

Go to your Podfile and add:

pod `CSafariWebKit`

Then in your terminal run:

pod install

Now you can open YourApp.xcworkspace

How to use it

First import the Framework in a ViewController that you want to use it.

import CSafariWebKit

SFSafariViewController

You can either receive it as a UIViewController to be presented :

let vc = WebView.safari.load(url: url)
self.present(vc, animated: true, completion: nil)

Or you can present it directly from your ViewController

    
    WebView.safari.present(url: URL, from previousViewController: UIViewController)
    
    WebView.safari.present(url: URL,
                           from previousViewController: UIViewController,
                           whenDidClose didClose: (() -> Void)?)
    
    WebView.safari.present(url: URL,
                           from previousViewController: UIViewController,
                           dismissButtonStyle: DismissButtonStyle,
                           whenDidClose didClose: (() -> Void)?)
    
    WebView.safari.present(url: URL,
                           from previousViewController: UIViewController,
                           dismissButtonStyle: DismissButtonStyle,
                           barTintColor: UIColor?,
                           tintColor: UIColor?,
                           whenDidClose didClose: (() -> Void)?)
    
    WebView.safari.present(url: URL,
                           from previousViewController: UIViewController,
                           dismissButtonStyle: DismissButtonStyle,
                           presentModally: Bool,
                           barCollapsingEnabled: Bool,
                           entersReaderIfAvailable: Bool,
                           barTintColor: UIColor?,
                           tintColor: UIColor?,
                           whenDidClose didClose: (() -> Void)?)

Where:

  • url - The URL to be loaded.
  • previousViewController - The ViewController that will present the Browser.
  • dismissButtonStyle - Indicates which button should be shown in SafariViewController to close it.
  • presentModally - Indicates if SafariViewController should be presented modally.
  • barCollapsingEnabled - Should enable collapsing of the navigation bar and hiding of the bottom toolbar when the user scrolls web content.
  • entersReaderIfAvailable - Indicates if SafariViewController should automatically show the Reader version of web pages. This will only happen when Safari Reader is available on a web page.
  • barTintColor - The tint color to apply to the navigation bar background.
  • tintColor - The tint color to apply to the navigation items and bar button items.
  • whenDidClose - A method used as a callback when the user closes the Browser.

WKWebView

You can either receive it as a UIViewController to be presented :

let vc = WebView.webview.load(url: url)
self.present(vc, animated: true, completion: nil)

Or you can present it directly from your ViewController

    WebView.wkWebView.present(url: URL, from previousViewController: UIViewController)
    
    WebView.wkWebView.present(url: URL,
                             from previousViewController: UIViewController,
                             whenDidClose didClose: (() -> Void)?)
    
    WebView.wkWebView.present(url: URL,
                             from previousViewController: UIViewController,
                             closeButtonName: String?,
                             buttonSide: ButtonSide,
                             barTintColor: UIColor?,
                             tintColor: UIColor?,
                             whenDidClose didClose: (() -> Void)?)
    
    WebView.wkWebView.present(url: URL,
                             from previousViewController: UIViewController,
                             closeButtonName: String?,
                             buttonSide: ButtonSide,
                             barTintColor: UIColor?,
                             tintColor: UIColor?,
                             title: String?,
                             whenDidClose didClose: (() -> Void)?)
    
    WebView.wkWebView.present(url: URL,
                             from previousViewController: UIViewController,
                             closeButtonName: String?,
                             buttonSide: ButtonSide,
                             barTintColor: UIColor?,
                             tintColor: UIColor?,
                             title: String?,
                             userAgent: String,
                             whenDidClose didClose: (() -> Void)?)

Where:

  • url - The URL to be loaded.
  • previousViewController - The ViewController that will present the Browser.
  • closeButtonName - Set a custom name to use as dismiss button.
  • closeButtonName - Set a custom name to use as dismiss button.
  • buttonSide - Indicates wich side the button should be presented.
  • barTintColor - The tint color to apply to the navigation bar background.
  • tintColor - The tint color to apply to the navigation items and bar button items.
  • title - Set a title for NavigationBar.
  • userAgent - Append a UserAgent to your WebView.
  • whenDidClose - A method used as a callback when the user closes the Browser.

Built With

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors