cordova-phone-call-trap
cordova-phone-call-trap copied to clipboard
onCall undefined
Hi guys im new at ionic and i install this plugin, i already import the module of js on app.component.ts, like this ``` `import {PhoneCallTrap} from 'io.gvox.plugin.phonecalltrap/www/PhoneCallTrap';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage:any = HomePage;
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
platform.ready().then(() => {
PhoneCallTrap.onCall(function(result) {
console.log("CHANGE STATE: " + result.state);
console.log("CALLER ID: " + result.number); // only in ringing state
switch (result.state) {
case "RINGING":
console.log("Phone is ringing", result.number);
break;
case "OFFHOOK":
console.log("Phone is off-hook");
}
});
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
});
}
};`
but when i do ionic serve, my console give me an error: Uncaught (in promise): TypeError: Cannot read property 'onCall' of undefined
TypeError: Cannot read property 'onCall' of undefined
Can you help me?
I am getting the same issue @kxylm did you get any solution on the same?
Did you solve the issue @anil1712 ?
Check that your config.xml file has the next line:
<plugin name="io.gvox.plugin.phonecalltrap" spec="^0.1.2" />
Then on your component you don't need the import line, instead you have to declare the PhoneCallTrap variable:
declare var PhoneCallTrap: any;
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage:any = HomePage;
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
platform.ready().then(() => {
PhoneCallTrap.onCall(function(result) {
console.log("CHANGE STATE: " + result.state);
console.log("CALLER ID: " + result.number); // only in ringing state
switch (result.state) {
case "RINGING":
console.log("Phone is ringing", result.number);
break;
case "OFFHOOK":
console.log("Phone is off-hook");
}
});
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
});
}
};
I think that should work