【问题标题】:Xamarin Forms Labs - TextingXamarin Forms Labs - 发短信
【发布时间】:2014-11-18 22:18:30
【问题描述】:

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

【问题讨论】:

  • 最好不要使用 XLabs,因为它们停止了对 xamarin 的贡献。

标签: xamarin.forms


【解决方案1】:

IPhoneService 中有:

 void SendSMS(string to, string body);

iOS 实现:

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

Android 实现:

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

WP 实现:

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");

【讨论】:

  • 我在课堂上怎么称呼它?
  • 它似乎还在当前源中:github.com/XForms/Xamarin-Forms-Labs/blob/…
  • 怎么会说它不存在呢?你试过了吗
  • 是的,几个版本之前。您是否在具有电话服务的设备上运行它?
  • 是的,我在 iphone 上运行它,我只是调用了 var device = Resolver.Resolve (); device.PhoneService.SendSMS("5015551212", "一条测试短信");但一直说 phoneservice 没有 SendSMS 的定义
【解决方案2】:

iOS SMS 发送未经测试,之前由于 URI 方法不允许消息正文而无法正常工作。如果您获得最新的源代码,它现在已经更新和测试(昨晚完成了实施)。您可以运行示例项目并测试通过电子邮件和 SMS 发送您当前的 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);
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-13
    • 2014-09-20
    • 2015-02-26
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 2015-09-18
    相关资源
    最近更新 更多