npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cordova-plugin-ortoo-safariviewcontroller

v1.4.0

Published

Forget InAppBrowser for iOS - this is way better for displaying read-only web content in your PhoneGap app.

Downloads

12

Readme

SafariViewController Cordova Plugin

by Eddy Verbruggen - @eddyverbruggen

0. Index

  1. Description
  2. Screenshots
  3. Installation
  4. Usage
  5. Advantages over InAppBrowser
  6. Changelog

1. Description

  • Use in cases where you'd otherwise use InAppBrowser
  • Use the new and powerful iOS9 viewcontroller to show webcontent in your PhoneGap app
  • Requires XCode 7 / iOS9 SDK to build
  • Requires iOS9 to use, lower versions need to fall back to InAppBrowser (example below!)

Note that I didn't decide to clobber window.open to override InAppBrowser when applicable because that would mean you could never use InAppBrowser in case you need its advanced features in one place and are happy with a simple readonly view in other cases.

2. Screenshots

As you can see from these shots: you can preload a page in reader mode or normal mode, and Safari gives you the option to use the share sheet!

Pressing 'Done' returns the user to your app as you'd expect.

       

3. Installation

To install the plugin with the Cordova CLI from npm:

$ cordova plugin add cordova-plugin-safariviewcontroller

Graceful fallback to InAppBrowser

Since SafariViewController is new in iOS9 you need to have a fallback for older versions (and other platforms), so if available returns false (see the snippet below) you want to open the URL in the InAppBrowser probably, so be sure to include that plugin as well:

$ cordova plugin add cordova-plugin-inappbrowser

I'm not including it as a depency as not all folks may have this requirement.

4. Usage

Check the demo code for an easy to drop in example, otherwise copy-paste this:

function openUrl(url, readerMode) {
  SafariViewController.isAvailable(function (available) {
    if (available) {
      SafariViewController.show({
            url: url,
            hidden: false, // default false. You can use this to load cookies etc in the background (see issue #1 for details).
            animated: false, // default true, note that 'hide' will reuse this preference (the 'Done' button will always animate though)
            transition: 'curl', // unless animated is false you can choose from: curl, flip, fade, slide (default)
            enterReaderModeIfAvailable: readerMode // default false
          },
          // this success handler will be invoked for the lifecycle events 'opened', 'loaded' and 'closed'
          function(result) {
            if (result.event === 'opened') {
              alert('opened');
            } else if (result.event === 'loaded') {
              alert('loaded');
            } else if (result.event === 'closed') {
              alert('closed');
            }
          },
          function(msg) {
            alert("KO: " + msg);
          })
    } else {
      // potentially powered by InAppBrowser because that (currently) clobbers window.open
      window.open(url, '_blank', 'location=yes');
    }
  })
}

function dismissSafari() {
  SafariViewController.hide()
}

5. Advantages over InAppBrowser

  • InAppBrowser uses the slow UIWebView (even when you're using a WKWebView plugin!), this plugin uses the ultra fast Safari Webview.
  • This is now Apple's recommended way to use a browser in your app.
  • A nicer / cleaner UI which is consistent with Safari and all other apps using a SFSafariViewController.
  • Since this is the system's main browser, assets like cookies are shared with your app, so the user is still logged on in his favorite websites.
  • Whereas cordova-plugin-inappbrowser is affected by ATS, this plugin is not. This means you can even load http URL's without whitelisting them.

6. Changelog

  • 1.4.0 Added a hidden property to show.
  • 1.3.0 isAvailable plays nice with non-iOS platforms. Added a transition property to show.
  • 1.2.0 Added lifecycle events to the success handler of show, and added the animated property to show.