Safari View Controller

Contents

For displaying read-only web content.

https://github.com/EddyVerbruggen/cordova-plugin-safariviewcontroller

Ionic Safari View Controller插件的安装(Installation)

ionic cordova plugin add cordova-plugin-safariviewcontroller npm install @ionic-native/safari-view-controller

Ionic Safari View Controller插件支持的平台(Supported Platforms)

  • Android
  • iOS

Ionic Safari View Controller插件的用法(Usage)

import { SafariViewController } from '@ionic-native/safari-view-controller';

constructor(private safariViewController: SafariViewController) { }

...

this.safariViewController.isAvailable()
  .then((available: boolean) => {
      if (available) {

        this.safariViewController.show({
          url: 'http://ionic.io',
          hidden: false,
          animated: false,
          transition: 'curl',
          enterReaderModeIfAvailable: true,
          tintColor: '#ff0000'
        })
        .subscribe((result: any) => {
            if(result.event === 'opened') console.log('Opened');
            else if(result.event === 'loaded') console.log('Loaded');
            else if(result.event === 'closed') console.log('Closed');
          },
          (error: any) => console.error(error)
        );

      } else {
        // use fallback browser, example InAppBrowser
      }
    }
  );