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

Hash code is not working on production release. TIMEOUT error is displayed. #26

Closed kendyl93 closed 3 years ago

kendyl93 commented 3 years ago

Current behavior: Sms comes and nothing happens. After some time the is the TIMEOUT error.

Expected behavior: App should read the sms activation code and paste it in the inputs in register page.

Related code:

Here you have my package.json

    "@angular/common": "~9.1.6",
    "@angular/core": "~9.1.6",
    "@angular/forms": "~9.1.6",
    "@angular/platform-browser": "~9.1.6",
    "@angular/platform-browser-dynamic": "~9.1.6",
    "@angular/router": "~9.1.6",
    "@capacitor/android": "^2.4.2",
    "@capacitor/core": "^2.4.2",
    "@capacitor/ios": "^2.4.2",
    "@ionic-native/core": "^5.0.7",
    "@ionic-native/file": "^5.29.0",
    "@ionic-native/fingerprint-aio": "^5.27.0",
    "@ionic-native/ionic-webview": "^5.29.0",
    "@ionic-native/mixpanel": "^5.27.0",
    "@ionic-native/open-native-settings": "^5.27.0",
    "@ionic-native/secure-storage": "^5.27.0",
    "@ionic-native/sms-retriever": "^5.29.0",
    "@ionic-native/splash-screen": "^5.0.0",
    "@ionic-native/status-bar": "^5.0.0",
    "@ionic/angular": "^5.0.0",
    "angular-fittext": "^2.1.1",
    "angular-i18next": "^10.0.0",
    "axios": "^0.19.2",
    "canvas-confetti": "^1.4.0",
    "capacitor-navigationbar": "0.0.2",
    "cordova-open-native-settings": "^1.5.2",
    "cordova-plugin-file": "^6.0.2",
    "cordova-plugin-fingerprint-aio": "^3.0.1",
    "cordova-plugin-mixpanel": "^4.7.0",
    "cordova-plugin-secure-storage-echo": "^5.0.1",
    "cordova-plugin-sms-retriever-manager": "^1.0.2",
    "country-phone-prefix": "^1.0.1",
    "hammerjs": "^2.0.8",
    "i18next": "^19.6.2",
    "ionic-image-loader": "^7.0.0-beta.2",
    "ionic-selectable": "^4.7.1",
    "ionicons": "^5.4.0",
    "jetifier": "^1.6.6",
    "mixpanel-browser": "^2.38.0",
    "moment": "^2.27.0",
    "rxjs": "~6.5.1",
    "tslib": "^1.10.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-builders/custom-webpack": "^9.2.0",
    "@angular-devkit/build-angular": "~0.901.5",
    "@angular/cli": "~9.1.5",
    "@angular/compiler": "~9.1.6",
    "@angular/compiler-cli": "~9.1.6",
    "@angular/language-service": "~9.1.6",
    "@capacitor/cli": "2.3.0",
    "@ionic/angular-toolkit": "^2.1.1",
    "@types/jasmine": "~3.5.0",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^12.11.1",
    "codelyzer": "^5.1.2",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~5.0.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~2.1.0",
    "karma-jasmine": "~3.0.1",
    "karma-jasmine-html-reporter": "^1.4.2",
    "protractor": "~5.4.3",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~3.8.3"
  },

Activation code service:

  import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { SmsRetriever } from '@ionic-native/sms-retriever/ngx';

@Injectable({
  providedIn: 'root',
})
export class ActivationService {
  public activationCode: BehaviorSubject<string> = new BehaviorSubject(null);

  constructor(private smsRetriever: SmsRetriever) {}

  public listenForAndroidSMS = () => {
    this.smsRetriever
      .startWatching()
      .then((res: any) => {
        const code = /[0-9]{6}/g.exec(res.Message)[0];
        if (code) {
          this.activationCode.next(code);
        }
      })
      .catch((error: any) => console.error(error));
  };

  public formatPhoneNumber = (number: string): string => {
    return number?.match(/[0-9]{1,3}/g).join(' ');
  };
}

and here I am listening for the sms code in the register page:

      const os = this.platform.is('android') ? 'android' : 'ios';
      if (os === 'android') {
        this.activationService.listenForAndroidSMS();
      }

Other information: I have the app made in IONIC(angular) and the hash was working for a few months but it stopped working for any reason. I've updated the hash code for three environments. Local, staging, and production. Staging and production are handled by Appcenter. Locally reading the SMS code is working as well as on staging. When it comes to the production version it is not working at all. I've also enabled the auto-fill option in the device settings.

I've tried to generate the code in two ways:

  1. getAppHash() - I've used this and displayed the hash code in the staging appcenter build.
  2. I've tried also to generate the hash with that script https://stackoverflow.com/questions/61455785/how-to-compute-hash-string-for-sms-retriever-api-in-ionic-v4

Both methods are working on staging and locally but not works on the production build.

I am not sure if I provide you enough information but I cannot show you my whole repo because it is private.

hanatharesh2712 commented 3 years ago

@kendyl93 Are you using the same hash for Prod and Staging App? If you are creating the app hash with signed APK then the hash should be different.

May help this: https://github.com/hanatharesh2712/ionic-native-sms-retriever-plugin-master/issues/22

kendyl93 commented 3 years ago

@kendyl93 Are you using the same hash for Prod and Staging App? If you are creating the app hash with signed APK then the hash should be different.

May help this: #22

Thanks for your answer. As I mentioned in the description. I tried to add the hash both ways. I put that hash the same for staging and production. Funny thing is that it was working but at some point, it stopped and I am not sure why it happened. Any ideas what change I provide that the hash stopped working?

To the link you posted above. I dont have any id attribute in <widget .... I am using capacitor and I signed the hash with package="es.myAwesomeApp.app" from AndroidManifest.xml file.

hanatharesh2712 commented 3 years ago

@kendyl93 I mean, The hash generated for Stagging app won't work for the Production app. You need to generate the new hash for the production build.

hanatharesh2712 commented 3 years ago

Closing as no response

MaYoRr commented 1 year ago

@kendyl93 I mean, The hash generated for Stagging app won't work for the Production app. You need to generate the new hash for the production build.

How to generate new hash?