Hi,
I want to build a custom Cordova plugin for my app, so I read some instructions, and I try to build the custom Ionic native to wrap the Cordova plugin. but I little confused why I always get the error said plugin_not_installed when I run the app.
here is my code, thanks.
Ionic native
/**
* This is a template for new plugin wrappers
*
* TODO:
* - Add/Change information below
* - Document usage (importing, executing main functionality)
* - Remove any imports that you are not using
* - Remove all the comments included in this template, EXCEPT the @Plugin wrapper docs and any other docs you added
* - Remove this note
*
*/
import { Injectable } from '@angular/core';
import { Plugin, Cordova, CordovaProperty, CordovaInstance, InstanceProperty, IonicNativePlugin } from '@ionic-native/core';
import { Observable } from 'rxjs';
/**
* @name mcpttsip
* @description
* This plugin does something
*
* @usage
* ```typescript
* import { mcpttsip } from '@ionic-native/mcpttsip';
*
*
* constructor(private mcpttsip: mcpttsip) { }
*
* ...
*
*
* this.mcpttsip.functionName('Hello', 123)
* .then((res: any) => console.log(res))
* .catch((error: any) => console.error(error));
*
* ```
*/
@Plugin({
pluginName: 'mcpttsip',
plugin: 'mcpttsip', // npm package name, example: cordova-plugin-camera
pluginRef: 'mcpttsip', // the variable reference to call the plugin, example: navigator.geolocation
repo: 'https://github.com/DieYiSu/mcpttSIPP2P.git', // the github repository URL for the plugin
install: '', // OPTIONAL install command, in case the plugin requires variables
installVariables: [], // OPTIONAL the plugin requires variables
platforms: ['Android'] // Array of platforms supported, example: ['Android', 'iOS']
})
@Injectable()
export class mcpttsip extends IonicNativePlugin {
/**
* This function does something
* @param arg1 {string} Some param to configure something
* @param arg2 {number} Another param to configure something
* @return {Promise<any>} Returns a promise that resolves when something happens
*/
// @Cordova()
// functionName(arg1: string, arg2: number): Promise<any> {
// return; // We add return; here to avoid any IDE / Compiler errors
// }
@Cordova()
init(userInfo: object): Promise<any> {
console.log(userInfo);
return;
}
@Cordova()
test(): Promise<any> {
console.log('test');
return;
}
// @Cordova()
// coolMethod(arg1: string): Promise<any> {
// return; // We add return; here to avoid any IDE / Compiler errors
// }
}
Corodva custom plugin
var exec = require('cordova/exec');
// exports.coolMethod = function (arg0, success, error) {
// exec(success, error, 'mcpttsip', 'coolMethod', [arg0]);
// };
module.exports = {
init: function(userInfo, successCallback, errorCallback){
console.log('init function');
console.log(userInfo);
}
}
login.page.ts
import { Component, OnInit} from '@angular/core';
import { FormsModule, FormGroup, FormBuilder } from '@angular/forms';
import { mcpttsip } from '@ionic-native/mcpttsip/ngx';
@Component({
selector: 'app-login',
templateUrl: './login.page.html',
styleUrls: ['./login.page.scss'],
})
export class LoginPage implements OnInit {
constructor(private mcpttsip: mcpttsip) { }
ngOnInit() { }
loginOnClick(userForm){
console.log('test');
console.log(userForm.value);
console.log(this.mcpttsip.init(userForm.value));
}
}