hanatharesh2712 / ionic-native-sms-retriever-plugin-master

Cross-platform plugin for Cordova / PhoneGap to Retrieve SMS. Available for Android.
27 stars 18 forks source link

Cannot read de property from the plugin #11

Closed eishynena closed 4 years ago

eishynena commented 4 years ago

core.js.pre-build-optimizer.js:9110 ERROR TypeError: Cannot read property 'getAppHash' of undefined at app (home.page.ts:17) at Object.handleEvent (home.page.ngfactory.js.pre-build-optimizer.js:16) at Object.handleEvent (core.js.pre-build-optimizer.js:38098) at Object.handleEvent (core.js.pre-build-optimizer.js:38879) at ts (core.js.pre-build-optimizer.js:25818) at core.js.pre-build-optimizer.js:37030 at HTMLButtonElement. (platform-browser.js.pre-build-optimizer.js:1789) at a.invokeTask (zone-evergreen.js.pre-build-optimizer.js:391) at Object.onInvokeTask (core.js.pre-build-optimizer.js:34182) at a.invokeTask (zone-evergreen.js.pre-build-optimizer.js:390)

I have a blank project just to use the plugin and test if all is fine with the connection with it. So, this is a simple test, this is in mi home.page.ts: import { Component } from '@angular/core'; import { SmsRetriever } from '@ionic-native/sms-retriever/ngx';

@Component({ selector: 'app-home', templateUrl: 'home.page.html', styleUrls: ['home.page.scss'], }) export class HomePage { private smsRetriever: SmsRetriever; constructor() {}

app(){ // This function is to get hash string of APP. // * @return {Promise} Returns a promise that resolves when successfully generate hash of APP. this.smsRetriever.getAppHash() .then((res: any) => console.log(res)) .catch((error: any) => console.error(error));

// This function start wathching message arrive event and retrive message text. // @return {Promise} Returns a promise that resolves when retrives SMS text or TIMEOUT after 5 min. this.smsRetriever.startWatching() .then((res: any) => console.log(res)) .catch((error: any) => console.error(error)); }

} And i made this to test the functions on mi home.page.html:

<button ion-button block type="button" id="startWatch" style="padding:4px;margin:4px 0" (click)="app();">Prueba

The plugin is already installed but looks like not connect o something like that. I'm new working with ionic and android so, i tried my best! ... maybe I forget something else?

Thank you!!

hanatharesh2712 commented 4 years ago

Please install the plugin with these commands:

ionic cordova plugin add cordova-plugin-sms-retriever-manager@latest

npm install @ionic-native/sms-retriever

After installing, call the plugin methods once platform ready method called.

posdevelopers commented 4 years ago

its not working on ionic 3 , can you please check it's giving below error

LoginProcessPage.html:71 ERROR TypeError: Object(...) is not a function at SmsRetriever.getAppHash (index.js:28) at LoginProcessPage.webpackJsonp.51.LoginProcessPage.getAppHashKey (login-process.ts:82) at Object.eval [as handleEvent] (LoginProcessPage.html:71) at handleEvent (core.js:13589) at callWithDebugContext (core.js:15098) at Object.debugHandleEvent [as handleEvent] (core.js:14685) at dispatchEvent (core.js:10004) at core.js:10629 at HTMLElement. (platform-browser.js:2628) at t.invokeTask (polyfills.js:3) View_LoginProcessPage0 @ LoginProcessPage.html:71 LoginProcessPage.html:71 ERROR CONTEXT DebugContext

hanatharesh2712 commented 4 years ago

You can find Ionic 3 working example: https://github.com/hanatharesh2712/sms-plugin-test-ionic-3

hanatharesh2712 commented 4 years ago

Code Sample for Ionic 3:

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { SmsRetriever } from '@ionic-native/sms-retriever/ngx';
var smsRetriever = window['cordova']['plugins']['smsRetriever'];

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  public smsTextmessage: string = '';
  public appHashString: string = '';

  constructor(public navCtrl: NavController, private smsRetriever: SmsRetriever) {

  }
  getHashCode() {
    smsRetriever['getAppHash']((res) => {
      this.appHashString = res;
      console.log(res);
    }, (err) => {
      console.warn(err);
    }
    );
  }

  getSMS() {
    smsRetriever['startWatching']((res) => {
      this.smsTextmessage = res.Message;
      console.log(res);
    }, (err) => {
      console.warn(err);
    }
    );
  }
}