1
votes

This is the plugin I'm trying to use: https://github.com/blinkmobile/cordova-plugin-sketch

Q) I'm trying to get the cordova sketch plugin working so I can annotate an image, but can't get this to initialise properly. What am I doing wrong?

The page loads fine and I don't get any error alert, which is the second callback function you can see.

Yes, I'm running on the device. I know cordova plugins don't work in the browser.

Page:

<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')
      }
    });
  }
}

Thanks!

2
What are the output of: console.log('DEBUG || ' + JSON.stringify(cordova.plugins));, console.log('DEBUG || ' + JSON.stringify(window.plugins));?? Sometimes it needs to be referenced differently. - Alex Bailey
{} and {"toast":{}} respectively. I'm also using the toast plugin. - Dave
What about console.log('DEBUG || ' + JSON.stringify(navigator)); - Alex Bailey
The reason I ask is that if(navigator && navigator.sketch) { doesn't seem to return true. - Alex Bailey
I've just put alert(1) under the if(navigator && navigator.sketch) statement, and it shows up. So something must be going wrong with the plugin? navigator.sketch json resolves to {} though. - Dave

2 Answers

0
votes

Have you tried to add your plugin in the config.xml file ?

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

From the developer:

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

I have found an alternative solution by following this tutorial:

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