Reputation: 659
I am using the xamarin forms labs package at the moment and I was wondering how I can use the phone feature from xamarin forms labs and send a text to the specified number
Upvotes: 1
Views: 1311
Reputation: 5234
The iOS SMS sending was not tested and it previously wasn't working correctly as the URI method doesn't allow message body. If you get the latest source it has now been updated and tested (finished the implementation last night). You can run the sample project and test sending your current GPS location with E-mail and SMS.
This is the SMS code for iOS:
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);
}
}
Upvotes: 2
Reputation: 9478
In IPhoneService
there is:
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();
}
To call it:
var device = Resolver.Resolve<IDevice> ();
device.PhoneService.SendSMS("5015551212", "a test sms message");
Upvotes: 6