简体   繁体   English

如何在Xamarin.Forms上发送短信

[英]How to Send SMS on Xamarin.Forms

I am developing Xamarin.Forms project, iOS, Android and Windows Phone. 我正在开发Xamarin.Forms项目,iOS,Android和Windows Phone。

My app ask the user to enter text Message and Phone number then on submit, I need to send SMS to the phone number. 我的应用程序要求用户输入短信和电话号码然后提交,我需要发送短信到电话号码。

I prefer to have a single implementation for all platforms. 我更喜欢为所有平台都有一个实现。

You can use this open source plugin Xam.Plugins.Messaging https://github.com/cjlotz/Xamarin.Plugins 你可以使用这个开源插件Xam.Plugins.Messaging https://github.com/cjlotz/Xamarin.Plugins

This is the provided example (from https://github.com/cjlotz/Xamarin.Plugins/blob/master/Messaging/Details.md ) : 这是提供的示例(来自https://github.com/cjlotz/Xamarin.Plugins/blob/master/Messaging/Details.md ):

// Make Phone Call
var phoneDialer = CrossMessaging.Current.PhoneDialer;
if (phoneDialer.CanMakePhoneCall) 
    phoneDialer.MakePhoneCall("+272193343499");

// Send Sms
var smsMessenger = CrossMessaging.Current.SmsMessenger;
if (smsMessenger.CanSendSms)
   smsMessenger.SendSms("+27213894839493", "Well hello there from Xam.Messaging.Plugin");

var emailMessenger = CrossMessaging.Current.EmailMessenger;
if (emailMessenger.CanSendEmail)
{
    // Send simple e-mail to single receiver without attachments, bcc, cc etc.
    emailMessenger.SendEmail("to.plugins@xamarin.com", "Xamarin Messaging Plugin", "Well hello there from Xam.Messaging.Plugin");

    // Alternatively use EmailBuilder fluent interface to construct more complex e-mail with multiple recipients, bcc, attachments etc. 
    var email = new EmailMessageBuilder()
      .To("to.plugins@xamarin.com")
      .Cc("cc.plugins@xamarin.com")
      .Bcc(new[] { "bcc1.plugins@xamarin.com", "bcc2.plugins@xamarin.com" })
      .Subject("Xamarin Messaging Plugin")
      .Body("Well hello there from Xam.Messaging.Plugin")
      .Build();

    emailMessenger.SendEmail(email);
}   

微软现在在其全新的全新https://docs.microsoft.com/en-us/xamarin/essentials NuGet包中提供此功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM