[英]Ionic2 - Using Cordova plugin
I just wanna use this Cordova
plugin: 我只是想使用这个Cordova
插件:
https://github.com/Rohfosho/CordovaCallNumberPlugin https://github.com/Rohfosho/CordovaCallNumberPlugin
For this purpose I created an Ionic2
brand new project with: 为此,我创建了一个Ionic2
全新项目:
$ ionic start ionic2-callnumber sidemenu --v2
$ cd ionic2-callnumber
$ ionic platform add android --save
$ ionic plugin add https://github.com/Rohfosho/CordovaCallNumberPlugin.git
On the web page of this plugin: 在这个插件的网页上:
https://github.com/Rohfosho/CordovaCallNumberPlugin https://github.com/Rohfosho/CordovaCallNumberPlugin
they say: 他们说:
Use the plugin in your JS file:
window.plugins.CallNumber.callNumber(onSuccess, onError, number, bypassAppChooser);
Then I did: 然后我做了:
home.ts home.ts
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
@Component( {
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
phone: string;
constructor( public navCtrl: NavController ) {
this.phone = "2129442720";
}
callNumber() {
window.plugins.CallNumber.callNumber(
function( result ) {
console.log( "Success:" + result );
},
function( result ) {
console.log( "Error:" + result );
},
this.phone,
true
);
}
}
home.html home.html的
<ion-header>
<ion-navbar>
<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-title>Home</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<h3>Ionic Menu Starter</h3>
<p>
If you get lost, the <a href="http://ionicframework.com/docs/v2">docs</a> will show you the way.
</p>
<button ion-button secondary menuToggle>Toggle Menu</button>
<div>
<button ion-button secondary (click)="callNumber()">Call Number</button>
<textarea style="width:100%;height:100px;">{{phone}}</textarea>
</div>
</ion-content>
but when I do: 但是当我这样做时:
$ ionic run android
I get the following error: 我收到以下错误:
My questions are: 我的问题是:
[1/2]
How can I make use of this plugin on this project? [1/2]
如何在这个项目中使用这个插件?
Here you have a link to this project I created for test: 在这里,您有一个我为测试创建的项目的链接:
https://github.com/napolev/ionic2-callnumber https://github.com/napolev/ionic2-callnumber
[2/2]
Given a Cordova plugin, how do I know the way I need to call the plugin? [2/2]
鉴于Cordova插件,我怎么知道我需要调用插件的方式?
For example, for this other plugin: @ionic-native/file-path
例如,对于这个其他插件: @ionic-native/file-path
https://github.com/hiddentao/cordova-plugin-filepath https://github.com/hiddentao/cordova-plugin-filepath
The way you use it is as follows: 你使用它的方式如下:
constructor(
...,
private filePath: FilePath
...,
) {
...
}
...
this.filePath.resolveNativePath(imagePath).then(imagePath => {
this.cameraUrl = imagePath;
this.photoSelected = true;
this.photoTaken = false;
});
I mean, it is different to the first plugin, where they specify: 我的意思是,它与第一个插件不同,它们指定:
window.plugins.CallNumber.callNumber(...);
Ionic has it own implementation of various Cordova plugins, called Ionic Native (you can access through https://ionicframework.com/docs/native . Ionic拥有各种Cordova插件的实现,称为Ionic Native(您可以通过https://ionicframework.com/docs/native访问)。
Given that you can install Ionic Native Call Number plugin with these steps: ionic plugin add --save call-number
and npm install --save @ionic-native/call-number
鉴于您可以使用以下步骤安装Ionic Native Call Number插件: ionic plugin add --save call-number
和npm install --save @ionic-native/call-number
then you can use it by: 然后你可以使用它:
import { CallNumber } from '@ionic-native/call-number'; constructor(private callNumber: CallNumber) { } this.callNumber.callNumber(18001010101, true) .then(() => console.log('Launched dialer!')) .catch(() => console.log('Error launching dialer'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.