1

我是 Ionic 的新手,我已经编写了代码,但我无法读取手机上收到的短信。在短信插件中我无法读取字符串。我的代码中是否有任何错误:下面是我的代码:

getSMS(){
     var filter = {
        box : 'inbox', // 'inbox' (default), 'sent', 'draft', 'outbox', 'failed', 'queued', and '' for all   
        // following 4 filters should NOT be used together, they are OR relationship
        // read : 0, // 0 for unread SMS, 1 for SMS already read
        // _id : 1234, // specify the msg id
        address : 'IM-WAYSMS', // sender's phone number
        // body : 'This is a test SMS', // content to match

        // following 2 filters can be used to list page up/down
        indexFrom : 0, // start from index 0
        maxCount : 10, // count of SMS to return each time
      };
      this.logger.debug("getSms");
      if(window.SMS) window.SMS.listSMS(filter, (data)=>{
          //Filterd Data
           this.logger.debug("checking the filter data " +JSON.stringify(data));
           this.text=data[0].body;
           this.logger.debug("checking the text " + this.text);
           **this.otpNumber = this.text.substring(Number(this.text.indexOf("'"))+Number(1), Number(this.text.lastIndexOf("'")))**
           this.logger.debug("checking the otpNumber "+this.otpNumber);

          if(this.otpNumber){
             //this.logger.post('')
             // .subscribe(this.otpNumber,this.loginId, (result,data,id)=>{
               //this is post call for validate Otp
                let OtpObj={
                 loginId: this.mobile,
                   otp:this.otpNumber
                 }
                this.logger.debug("checking the otpNumber "+this.otpNumber);
                this.rest.post('/validateOTP' ,OtpObj)

            .subscribe( (result)=>{
                  this.logger.debug("checking data of success " +JSON.stringify(result));
               if(result == '1') {
                 this.access_token = result.access_token;
                 this.firstDiv=false;
                 this.secondDiv = true;
                 this.logger.debug("checking access tocken "+ this.access_token);
                 alert("otp success");
               }
               else{
                 this.logger.error("error of otp"+data);
                 }
              });
            }
              else{
              this.logger.info("no otpnumber");
            }
            // return _this.otpNumber;   
          }, (err)=>{
          this.logger.debug("checking the err "+JSON.stringify(err));
        });
      }
4

0 回答 0