【问题标题】:How to wait for the permission request to access the sms to be confirmed如何等待访问短信的权限请求被确认
【发布时间】:2019-10-08 01:00:20
【问题描述】:

我必须给我的几个联系人发短信。

在请求权限时,应用程序完全崩溃。重新启动应用程序后,将发送短信。我认为问题在于应用程序不等待确认许可。问题出在安卓上。

    sms.contacts.forEach(async contact => {
      try {
        // Send sms
        await this.sms.send(contact.phoneNumbers[0].value, this.messageText)
      } catch (error) {
        this.errorsMsg.push(error)
        this.isOk = false
      }
    })

有人可以帮助我吗?

【问题讨论】:

  • 我认为您的逻辑有误。看看这个 - 你是否使用 async/await 语法,但只在你的 forEach 循环内。 IMO 这导致第一次成功等待代码允许应用程序进入应用程序的下一部分。更多细节结束更好的解释,你可以找到租用:stackoverflow.com/a/37576787/2972087

标签: javascript angular ionic-framework ionic3 cordova-plugins


【解决方案1】:

感谢kris_IV 的帮助。

作为this post says,我只需要使用for循环

for (const contact of sms.contacts) {
  try {
    await this.sms.send(contact.phoneNumbers[0].value, this.messageText)
  } catch (error) {
    this.errorsMsg.push(error)
    this.isOk = false
  }
}

【讨论】:

    猜你喜欢
    • 2021-11-04
    • 2020-07-20
    • 1970-01-01
    • 2015-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多