【问题标题】:How to trigger SMS URI redirect in React-Native for multiple phone numbers?如何在 React-Native 中为多个电话号码触发 SMS URI 重定向?
【发布时间】:2020-04-30 08:19:22
【问题描述】:

所以基本上我有一个代码已经在安卓设备上工作了,它的目的是触发设备的消息/短信应用程序,其中包含预填充的文本。这也会在 iOS 上打开 iMessage 应用程序,并且消息已成功预填充,但不幸的是它不支持多个电话号码。

以下代码目前是我正在尝试做的一个示例。 generateURI() 的返回值稍后用于 react native 的 Linking.openURL() 命令。

export function generateURI(arrayOfPhoneNumbers, event) {
  var url = `sms:`

  for(var i = 0; i < arrayOfPhoneNumbers.length; i++) {
    url += `${arrayOfPhoneNumbers[i]},`
  }
  url = url.slice(0, -1); //remove last comma
  url += `${getSMSDivider()}body=Test Message`

  return url
}

function getSMSDivider() {
  return Platform.OS === "ios" ? "&" : "?";
}

值得注意的事情:

Apple 似乎不尊重许多 URI 方案模式和标准,因为它们在以下链接中列出:https://www.rfc-editor.org/rfc/rfc5724。例如:每个 sms 字段都应该使用字符 ?,但对于 iOS 设备,只有 &amp; 有效,此外,如果您对作为 body= 属性传递的字符串值进行编码,android 可以很好地理解它,但 iPhone 不会不。因此,不幸的是,在处理 Apple 自己的规则手册时,查看文档化标准并不是一个可行的解决方案。

另外苹果在下面的链接https://developer.apple.com/library/archive/featuredarticles/iPhoneURLScheme_Reference/SMSLinks/SMSLinks.html上有一个很奇怪的说法The URL string must not include any message text or other information. 但这并不意味着它们不支持多个电话号码。

【问题讨论】:

    标签: ios react-native redirect sms uri


    【解决方案1】:

    这对我有用:

    let numbers = '';
    contacts.forEach((phoneNumber: string) => {
      numbers += `${phoneNumber},`;
    });
    numbers = numbers.slice(0, -1);
    
    const url = (Platform.OS === 'android')
      ? `sms:${numbers}?body=${text}`
      : `sms:/open?addresses=${numbers}&body=${text}`;
    

    【讨论】:

    • 嘿@denisas,感谢您的解决方案!它对我很好!也没有:/open? 部分,仅使用“地址”属性来跟踪数字:)
    猜你喜欢
    • 1970-01-01
    • 2019-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-13
    • 1970-01-01
    • 2017-08-28
    相关资源
    最近更新 更多