离子变量损失

Ionic variable loss

我正在编写一个允许我的 RPI 通过蓝牙连接到互联网的应用程序 这部分有效,但我试图将我的 RPI 的 ID 存储在 phone 上, 问题是我的变量丢失了它们的值 (null)

这是代码

              timeout(10000).then( () => {
              this.ble.read(
                this.deviceID,
                this.uuidConfig.serviceUUID,
                this.uuidConfig.readStatusUUID,
              ).then( (data) => {
                  const status = JSON.parse(new TextDecoder().decode(data));
                  if (this.ble.isConnected) {
                    if(status.ID !== undefined){
                      this.presentToast("Success !");
                      this.storage.get('SpectR').then(spectrID => {
                     // At this exact location, status.ID is null, I don't get whyy
                        if (spectrID === null){
                          let arrId = status.ID.split()
                          this.storage.set('SpectR', arrId ).then(r => console.log('done') )
                        }
                        else{
                          spectrID.push(status.ID)
                          this.storage.set('SpectR', spectrID ).then(r => console.log('done') )
                        }
                      })
                      this.navCtrl.back()
                    } else {
                      this.presentToast("Wrong password :/")
                    }
                  } else if (!this.ble.isConnected) {
                    this.presentToast("Something went wrong :/")
                  }
                }
              )
            }
          )

你有什么想法吗? 在添加存储部分之前,该值从未被覆盖

试试Debug,问题我还不能评论...回复status的值

timeout(10000).then(() => {
    this.ble.read(
        this.deviceID,
        this.uuidConfig.serviceUUID,
        this.uuidConfig.readStatusUUID,
    ).then((data) => {
        const status = JSON.parse(new TextDecoder().decode(data));
        // DEBUG START
        // DEBUG START
        // DEBUG START
        console.info('DEBUG START')
        console.log({ status })
        console.info('DEBUG END')
        // DEBUG END
        // DEBUG END
        // DEBUG END
        if (this.ble.isConnected) {
            if (status.ID !== undefined) {
                this.presentToast("Success !");
                this.storage.get('SpectR').then(spectrID => {
                    // At this exact location, status.ID is null, I don't get whyy
                    if (spectrID === null) {
                        let arrId = status.ID.split()
                        this.storage.set('SpectR', arrId).then(r => console.log('done'))
                    }
                    else {
                        spectrID.push(status.ID)
                        this.storage.set('SpectR', spectrID).then(r => console.log('done'))
                    }
                })
                this.navCtrl.back()
            } else {
                this.presentToast("Wrong password :/")
            }
        } else if (!this.ble.isConnected) {
            this.presentToast("Something went wrong :/")
        }
    }
    )
}
)