cordova-phone-call-trap icon indicating copy to clipboard operation
cordova-phone-call-trap copied to clipboard

onCall undefined

Open kxylm opened this issue 7 years ago • 3 comments

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?

kxylm avatar Jun 20 '17 17:06 kxylm

I am getting the same issue @kxylm did you get any solution on the same?

anil1712 avatar Sep 13 '17 06:09 anil1712

Did you solve the issue @anil1712 ?

abrahamadebayo avatar Jan 22 '18 06:01 abrahamadebayo

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

arraintxo avatar Jul 26 '18 17:07 arraintxo