【问题标题】:In xamarin.form How we can send sms with xamarin.form?在 xamarin.form 我们如何使用 xamarin.form 发送短信?
【发布时间】:2019-11-19 09:31:16
【问题描述】:

我是 xamarin.form 的新手,我想自动向电话号码发送短信。有没有免费的解决方案?我正在做一个简单的项目。

【问题讨论】:

    标签: c# xamarin xamarin.forms xamarin.android xamarin.ios


    【解决方案1】:

    要在 Xamarin.Forms 中发送消息,您需要使用 nuget 包管理器中的 Xamarin.Essentials 插件

    发送消息的代码

    public async Task SendSms(string messageText, string recipient)
    {
        var message = new SmsMessage(messageText, new []{ recipient });
        await Sms.ComposeAsync(message);
    }
    

    欲了解更多信息,请访问 https://docs.microsoft.com/en-us/xamarin/essentials/sms

    【讨论】:

      【解决方案2】:

      在你的 nuget 包中添加 Xamarin.Essentials 并尝试以下代码:

      public async Task SendSms(string messageText, string recipient) 
      {
          try
          {
              var message = new SmsMessage(messageText, new []{ recipient });
              await Sms.ComposeAsync(message);
          }
          catch (FeatureNotSupportedException ex)
          {
              // Sms is not supported on this device.
          }
          catch (Exception ex)
          {
              // Other error has occurred.
          }
      }
      

      如果您必须发送给多个收件人,请将参数“字符串收件人”更改为收件人数组“字符串 [] 收件人”。 如果您需要进一步的帮助,请告诉我。

      【讨论】:

        猜你喜欢
        • 2018-03-12
        • 1970-01-01
        • 2020-03-04
        • 2018-02-06
        • 2016-12-06
        • 2018-09-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多