How to use the @ionic-native/core.CordovaCheck function in @ionic-native/core

To help you get started, we’ve selected a few @ionic-native/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ionic-team / ionic-native / src / @ionic-native / plugins / ibeacon / index.ts View on Github external
@Plugin({
  pluginName: 'IBeacon',
  plugin: 'cordova-plugin-ibeacon',
  pluginRef: 'cordova.plugins.locationManager',
  repo: 'https://github.com/petermetz/cordova-plugin-ibeacon',
  platforms: ['Android', 'iOS']
})
@Injectable()
export class IBeacon extends IonicNativePlugin {
  /**
   * Instances of this class are delegates between the {@link LocationManager} and
   * the code that consumes the messages generated on in the native layer.
   *
   * @returns {IBeaconDelegate} An instance of the type {@type Delegate}.
   */
  @CordovaCheck({ sync: true })
  Delegate(): IBeaconDelegate {
    const delegate = new cordova.plugins.locationManager.Delegate();

    delegate.didChangeAuthorizationStatus = (pluginResult?: IBeaconPluginResult) => {
      return new Observable(
        (observer: any) => {
          const cb = (data: IBeaconPluginResult) => observer.next(data);
          return delegate.didChangeAuthorizationStatus = cb;
        }
      );
    };

    delegate.didDetermineStateForRegion = (pluginResult?: IBeaconPluginResult) => {
      return new Observable(
        (observer: any) => {
          const cb = (data: IBeaconPluginResult) => observer.next(data);
github ionic-team / ionic-native / src / @ionic-native / plugins / hot-code-push / index.ts View on Github external
/**
   * Show dialog with the request to update application through the Store (App Store or Google Play).
   * @param message {string} Message to show in the dialog
   * @returns {Promise} Resolves when the user is redirected to the store, rejects if the user declines.
   */
  @Cordova()
  requestApplicationUpdate(message: string): Promise {
    return;
  }

  /**
   * Download updates from the server-side.
   * @param options {HotCodePushRequestOptions} Additional options to the request. If not set - preferences from config.xml are used.
   * @returns {Promise} Resolves if there is an update available, rejects otherwise.
   */
  @CordovaCheck()
  fetchUpdate(options?: HotCodePushRequestOptions): Promise {
    return new Promise((resolve, reject) => {
      HotCodePush.getPlugin().fetchUpdate(
        (error: HotCodePushError, data: any) => {
          if (error) {
            reject(error);
          } else {
            resolve(data);
          }
        },
        options
      );
    });
  }

  /**
github ionic-team / ionic-native / src / @ionic-native / plugins / sqlite / index.ts View on Github external
pluginRef: 'sqlitePlugin',
  plugin: 'cordova-sqlite-storage',
  repo: 'https://github.com/litehelpers/Cordova-sqlite-storage',
  platforms: ['Android', 'iOS', 'macOS', 'Windows']
})
@Injectable()
export class SQLite extends IonicNativePlugin {
  /**
   * Open or create a SQLite database file.
   *
   * See the plugin docs for an explanation of all options: https://github.com/litehelpers/Cordova-sqlite-storage#opening-a-database
   *
   * @param config {SQLiteDatabaseConfig} database configuration
   * @return Promise
   */
  @CordovaCheck()
  create(config: SQLiteDatabaseConfig): Promise {
    return new Promise((resolve, reject) => {
      sqlitePlugin.openDatabase(
        config,
        (db: any) => resolve(new SQLiteObject(db)),
        reject
      );
    });
  }

  /**
   * Verify that both the Javascript and native part of this plugin are installed in your application
   * @returns {Promise}
   */
  @Cordova()
  echoTest(): Promise {
github ionic-team / ionic-native / src / @ionic-native / plugins / email-composer / index.ts View on Github external
}
        });
      } else {
        EmailComposer.getPlugin().getClients((apps: string[]) => {
          resolve(apps.length && apps.length > 0);
        });
      }
    });
  }

  /**
   * Returns an array of email clients installed on the device.
   *
   * @returns {Promise} Resolves if available, rejects if not available
   */
  @CordovaCheck()
  @Cordova({ platforms: ['Android'] })
  getClients(): Promise {
    return getPromise(resolve => {
      EmailComposer.getPlugin().getClients((apps: any) => {
        if (Object.prototype.toString.call(apps) === '[object String]') {
          apps = [apps];
      }
        resolve(apps);
      });
    });
  }

  /**
   * Verifies if sending emails is supported on the device.
   *
   * @param {string} [app] App id or uri scheme.
github ionic-team / ionic-native / src / @ionic-native / plugins / email-composer / index.ts View on Github external
resolve(true);
        } else {
          resolve(false);
        }
      });
    });
  }

  /**
   * Verifies if a specific email client is installed on the device.
   *
   * @param {string} [app] App id or uri scheme.
   * @returns {Promise} Resolves if available, rejects if not available
   */

  @CordovaCheck()
  hasClient(app?: string): Promise {
    return getPromise((resolve) => {
      if (app) {
        EmailComposer.getPlugin().hasClient(app, (result: boolean) => {
          if (result) {
            resolve(true);
          } else {
            resolve(false);
          }
        });
      } else {
        EmailComposer.getPlugin().getClients((apps: string[]) => {
          resolve(apps.length && apps.length > 0);
        });
      }
    });
github ionic-team / ionic-native / src / @ionic-native / plugins / secure-storage / index.ts View on Github external
*/
@Plugin({
  pluginName: 'SecureStorage',
  plugin: 'cordova-plugin-secure-storage-echo',
  pluginRef: 'cordova.plugins.SecureStorage',
  repo: 'https://github.com/mibrito707/cordova-plugin-secure-storage-echo',
  platforms: ['Android', 'Browser', 'iOS', 'Windows']
})
@Injectable()
export class SecureStorage extends IonicNativePlugin {
  /**
   * Creates a namespaced storage.
   * @param store {string}
   * @returns {Promise}
   */
  @CordovaCheck()
  create(store: string): Promise {
    return getPromise((res: Function, rej: Function) => {
      const instance = new (SecureStorage.getPlugin())(
        () => res(new SecureStorageObject(instance)),
        rej,
        store
      );
    });
  }
}
github ionic-team / ionic-native / src / @ionic-native / plugins / printer / index.ts View on Github external
export class Printer extends IonicNativePlugin {

  /**
   * Checks whether the device is capable of printing (uses `check()` internally)
   * @returns {Promise}
   */
  isAvailable(): Promise {
    return this.check()
      .then((res: any) => Promise.resolve(res.avail));
  }

  /**
   * Checks To check if printing is supported in general
   * @return {Promise} returns a promise that resolve with an object indicating whether printing is available
   */
  @CordovaCheck()
  check(): Promise {
    return getPromise((resolve: Function) => {
      Printer.getPlugin()
        .canPrintItem((avail: boolean, count: any) => {
          resolve({ avail, count });
        });
    });
  }

  /**
   * Displays a system interface allowing the user to select an available printer. To speak with a printer directly you need to know the network address by picking them before via `printer.pick`.
   * @returns {Promise}
   */
  @Cordova()
  pick(): Promise {
    return;
github ionic-team / ionic-native / src / @ionic-native / plugins / email-composer / index.ts View on Github external
EmailComposer.getPlugin().getClients((apps: any) => {
        if (Object.prototype.toString.call(apps) === '[object String]') {
          apps = [apps];
      }
        resolve(apps);
      });
    });
  }

  /**
   * Verifies if sending emails is supported on the device.
   *
   * @param {string} [app] App id or uri scheme.
   * @returns {Promise} Resolves if available, rejects if not available
   */
  @CordovaCheck()
  isAvailable(app?: string): Promise {
    return getPromise((resolve) => {
      Promise.all([this.hasAccount, this.hasClient(app)])
        .then((results) => {
          return resolve(results.length === 2 && results[0] && results[1]);
        });
    });
  }

  /**
   * Displays the email composer pre-filled with data.
   *
   * @param {EmailComposerOptions} options Email
   * @param {any} [scope] Scope for the promise
   * @returns {Promise} Resolves promise when the EmailComposer has been opened
   */
github ionic-team / ionic-native / src / @ionic-native / plugins / abbyy-rtr / index.ts View on Github external
AbbyyRtrSdk.startTextCapture((result: DataCaptureResult) => {
        if (result.error) {
          reject(result);
        } else {
          resolve(result);
        }
      }, options);
    });
  }

  /**
   * Opens a modal dialog with controls for the Data Capture scenario.
   * @param {DataCaptureOptions} options
   * @return {Promise}
   */
  @CordovaCheck()
  startDataCapture(options: DataCaptureOptions): Promise {
    return new Promise((resolve, reject) => {
      AbbyyRtrSdk.startDataCapture((result: DataCaptureResult) => {
        if (result.error) {
          reject(result);
        } else {
          resolve(result);
        }
      }, options);
    });
  }
}