我正在开发 Xamarin.Forms 项目,iOS,Android和Windows Phone。
我的应用程序要求用户输入短信和电话号码然后提交,我需要发送短信到电话号码。
我更喜欢为所有平台提供单一实现。
答案 0 :(得分:8)
您可以使用此开源插件 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);
}
答案 1 :(得分:1)
Microsoft现在在其全新的https://docs.microsoft.com/en-us/xamarin/essentials NuGet软件包中具有此功能。