Ionic2 + cordova-plugin-sketch

Ionic2 + cordova-plugin-sketch

这是我正在尝试使用的插件: https://github.com/blinkmobile/cordova-plugin-sketch

Q) 我试图让 cordova s​​ketch 插件工作,以便我可以注释图像,但无法正确初始化它。我做错了什么?

页面加载正常,我没有收到任何错误提示,这是您可以看到的第二个回调函数。

是的,我在设备上 运行。我知道 cordova 插件在浏览器中不起作用。

页数:

<ion-navbar *navbar header-colour>
  <button menuToggle>
    <ion-icon name="menu"></ion-icon>
  </button>
  <ion-title>Sketch</ion-title>
</ion-navbar>
<ion-content padding>
  <img #sketchElement src="img/sketchpad.jpg" height="400" width="600"/>
</ion-content>

Class:

import {NavController, NavParams} from 'ionic-framework/ionic';
import {Page, ViewController, Platform, Alert, Modal, Events} from 'ionic-framework/ionic';
import {forwardRef} from 'angular2/core';
import {OnInit, OnDestroy} from 'angular2/core';
import {ViewChild, ElementRef} from 'angular2/core';


@Page({
  templateUrl: 'build/pages/sketch/sketch.html'
})
export class SketchPage {
  @ViewChild('sketchElement') sketchElement:ElementRef;

  constructor(
    private _platform: Platform,
    private _nav: NavController,
    private _viewController: ViewController,
    private _events: Events) {
  }

  ngOnInit() {
    this._platform.ready().then(() => {
      if(navigator && navigator.sketch) {
        navigator.sketch.getSketch(
          function() {
          },
          function(message) {
            alert(message);
          },
          {
          destinationType: navigator.sketch.DestinationType.DATA_URL,
          encodingType: navigator.sketch.EncodingType.JPEG,
          inputType : navigator.sketch.InputType.FILE_URI,
          inputData : this.sketchElement.nativeElement.src
        });

        alert('done')
      }
    });
  }
}

谢谢!

您是否尝试过在 config.xml 文件中添加您的插件?

<gap:plugin name="cordova-plugin-sketch" source="npm" />

来自开发者:

This is only a windows plugin, we are going to release iOS/Android support in near feature, but not now.

我按照本教程找到了替代解决方案:

https://devdactic.com/signature-drawpad-ionic/