如何在 Xamarin.Forms 上发送短信
How to Send SMS on Xamarin.Forms
我正在开发 Xamarin.Forms 项目,iOS、Android 和 Windows Phone。
我的应用要求用户输入短信和 Phone 号码,然后在提交时,我需要向 phone 号码发送短信。
我更喜欢对所有平台使用单一实现。
你可以使用这个开源插件Xam.Plugins.Messaging
https://github.com/cjlotz/Xamarin.Plugins
这是提供的例子(来自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);
}
Microsoft 现在在其新的包罗万象的 https://docs.microsoft.com/en-us/xamarin/essentials NuGet 程序包中具有此功能。
我正在开发 Xamarin.Forms 项目,iOS、Android 和 Windows Phone。
我的应用要求用户输入短信和 Phone 号码,然后在提交时,我需要向 phone 号码发送短信。
我更喜欢对所有平台使用单一实现。
你可以使用这个开源插件Xam.Plugins.Messaging https://github.com/cjlotz/Xamarin.Plugins
这是提供的例子(来自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);
}
Microsoft 现在在其新的包罗万象的 https://docs.microsoft.com/en-us/xamarin/essentials NuGet 程序包中具有此功能。