SafariViewController Cordova Plugin
by Eddy Verbruggen - @eddyverbruggen
- 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.
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.
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),
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.
Check the demo code for an easy to drop in example, otherwise copy-paste this:
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
- 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.
cordova-plugin-inappbrowseris affected by ATS, this plugin is not. This means you can even load
httpURL's without whitelisting them.
- 1.4.0 Added a
isAvailableplays nice with non-iOS platforms. Added a
- 1.2.0 Added lifecycle events to the success handler of
show, and added the