Xamarin Forms Labs - 发短信

时间:2014-08-15 15:40:17

标签: xamarin.forms

我目前正在使用xamarin表格实验室软件包,我想知道如何使用xamarin表单实验室的电话功能并将文本发送到指定的号码

2 个答案:

答案 0 :(得分:6)

IPhoneService中有:

 void SendSMS(string to, string body);

iOS impl:

public void SendSMS(string to, string body)
        {
            UIApplication.SharedApplication.OpenUrl(new MonoTouch.Foundation.NSUrl("sms:" + to));
        }

Android impl:

 public void SendSMS(string to, string body)
        {
            SmsManager.Default.SendTextMessage(to, null, body, null, null);
        }

WP impl:

public void SendSMS(string to, string body)
        {
            new SmsComposeTask{ To = to, Body = body }.Show();
        }

要打电话:

var device = Resolver.Resolve<IDevice> ();
device.PhoneService.SendSMS("5015551212", "a test sms message");

答案 1 :(得分:2)

iOS短信发送未经过测试,之前由于URI方法不允许邮件正文,因此无法正常运行。如果你得到最新的资源,它现在已经更新和测试(昨晚完成了实施)。您可以运行示例项目并测试使用电子邮件和短信发送当前的GPS位置。

https://github.com/XForms/Xamarin-Forms-Labs/blob/master/samples/Xamarin.Forms.Labs.Sample/ViewModel/GeolocatorViewModel.cs

这是iOS的短信代码:

https://github.com/XForms/Xamarin-Forms-Labs/blob/master/src/Xamarin.Forms.Labs/Xamarin.Forms.Labs.iOS/Services/PhoneService.cs

    public void SendSMS(string to, string body)
    {
        if (this.CanSendSMS)
        {
            var smsController = new MFMessageComposeViewController()
            {
                Body = body,
                Recipients = new[] { to }
            };

            UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(smsController, true, null);
        }
    }